12511: readable_by filters on is_trashed directly
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Mon, 11 Dec 2017 16:54:52 +0000 (11:54 -0500)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Mon, 11 Dec 2017 19:21:34 +0000 (14:21 -0500)
commit363fc6395f866a9631f41630cbff49ac53e9a211
tree76374fb411c71f6f6a9fbee5b200380a4b00dc58
parent7e9baf1a750d769b4d0053cfe5a67b367a40056c
12511: readable_by filters on is_trashed directly

Fix performance problem in the negative join NOT EXISTS(...) used to filter out
trashed items for admin users.  The clause
(uuid = target_uuid OR owner_uuid = target_uuid) doesn't use the index
efficiently and results in a very expensive seq scan.

However, the "OR" in the negative clause is not necessary.  We only need
materialized_permission_view to know if "owner_uuid" is trashed (directly or
indirectly), not "uuid".  If the record type has an is_trashed flag (currently
only collections and groups) then it is more efficient to filter on that
directly.

This commit refactors the readable_by query to only check owner_uuid, and
additionally filter on "is_trashed" for collections and groups.

As an additional cleanup, because "readable_by" now explicitly knows to filter
on "is_trashed" this makes the default_scope in Collections redundant.  This
commit also removes default_scope & various uses of unscoped reduces complexity.

Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>
services/api/app/controllers/arvados/v1/collections_controller.rb
services/api/app/controllers/arvados/v1/groups_controller.rb
services/api/app/models/arvados_model.rb
services/api/app/models/collection.rb
services/api/app/models/container.rb
services/api/app/models/container_request.rb
services/api/lib/sweep_trashed_collections.rb
services/api/test/functional/arvados/v1/collections_controller_test.rb
services/api/test/unit/collection_test.rb
services/api/test/unit/container_test.rb