For each of the account's projects, this ran 9 separate queries: 1 for the accounts, and 1 for each of the 8 resource associations. Change this to 8-9 queries total. Add a first_project_with_resources dataset method to Project. This methods issues one query per resource association to find any objects related to the project in the dataset, using Sequel's filtering by associations support. If it finds a related object, it returns the project related to the object. To handle the filtering for projects with only a single account, use a subquery that checks that the access_tag table only has one entry for the project.
9.1 KiB
9.1 KiB