[openSUSE/open-build-service] 5ae63b: Eager load project when fetching packages in Watch...

Branch: refs/heads/master Home: https://github.com/openSUSE/open-build-service Commit: 5ae63b64ea4bc475de151e2520407e2a6f748387 https://github.com/openSUSE/open-build-service/commit/5ae63b64ea4bc475de151e... Author: Dany Marcoux <dmarcoux@posteo.de> Date: 2022-02-22 (Tue, 22 Feb 2022) Changed paths: M src/api/app/components/watchlist_component.rb Log Message: ----------- Eager load project when fetching packages in WatchlistComponent This removes N+1 queries, as we need the project in the method `toggle_watchable_path`. Commit: b570056ba232cd65e73cfc5c74f6e888ae4e23a6 https://github.com/openSUSE/open-build-service/commit/b570056ba232cd65e73cfc... Author: Dany Marcoux <dmarcoux@posteo.de> Date: 2022-02-22 (Tue, 22 Feb 2022) Changed paths: M src/api/app/components/watchlist_component.rb Log Message: ----------- Check if object is a watched item with a single query As an example for a watched item with a watchable being a package. Before, we executed 2 queries. 1. Fetching all columns of the watched item: SELECT `watched_items`.* FROM `watched_items` WHERE `watched_items`.`user_id` = 1 AND `watched_items`.`watchable_type` = 'Package' AND `watched_items`.`watchable_id` = 3 LIMIT 1 2. Fetching the watchable (a package): SELECT `packages`.* FROM `packages` WHERE `packages`.`id` NOT IN (SELECT `packages`.`id` FROM `packages` WHERE `packages`.`project_id` = 0) AND `packages`.`id` = 3 Now, we execute 1 query: SELECT 1 AS one FROM `watched_items` WHERE `watched_items`.`user_id` = 1 AND `watched_items`.`watchable_type` = 'Package' AND `watched_items`.`watchable_id` = 3 LIMIT 1 While testing locally, it tends to be a bit faster by about 1ms. It's definitely more in production since the database has more workload, so executing more queries tends to be more expensive. Commit: b50859b6f193dbdabee58f507b0af50cd25bb2cb https://github.com/openSUSE/open-build-service/commit/b50859b6f193dbdabee58f... Author: Dany Marcoux <danymarcoux@gmail.com> Date: 2022-02-23 (Wed, 23 Feb 2022) Changed paths: M src/api/app/components/watchlist_component.rb Log Message: ----------- Merge pull request #12243 from dmarcoux/queries-watchlist Improve queries in WatchlistComponent Compare: https://github.com/openSUSE/open-build-service/compare/80f03ed7127f...b50859...
participants (1)
-
Dany Marcoux