[obs-commits] [openSUSE/open-build-service] 5f77a0: Avoid N+1 queries in update policy
Branch: refs/heads/master Home: https://github.com/openSUSE/open-build-service Commit: 5f77a024cba5d20f65b4c280d0cdb943c49cb762 https://github.com/openSUSE/open-build-service/commit/5f77a024cba5d20f65b4c2... Author: Stephan Kulow <coolo@suse.de> Date: 2018-12-20 (Thu, 20 Dec 2018) Changed paths: M src/api/app/models/project.rb Log Message: ----------- Avoid N+1 queries in update policy has_remote_repositories? is called from project update? policy, which is called in a lot of places. And it's horribly slow as it loops through an array with N+1 queries looking like this in logs: DownloadRepository Exists (0.1ms) SELECT 1 AS one FROM `download_repositories` WHERE `download_repositories`.`repository_id` = 357782 LIMIT 1 DownloadRepository Exists (0.2ms) SELECT 1 AS one FROM `download_repositories` WHERE `download_repositories`.`repository_id` = 157220 LIMIT 1 DownloadRepository Exists (0.1ms) SELECT 1 AS one FROM `download_repositories` WHERE `download_repositories`.`repository_id` = 214402 LIMIT 1 DownloadRepository Exists (0.1ms) SELECT 1 AS one FROM `download_repositories` WHERE `download_repositories`.`repository_id` = 289102 LIMIT 1 DownloadRepository Exists (0.1ms) SELECT 1 AS one FROM `download_repositories` WHERE `download_repositories`.`repository_id` = 264047 LIMIT 1 DownloadRepository Exists (0.1ms) SELECT 1 AS one FROM `download_repositories` WHERE `download_repositories`.`repository_id` = 320882 LIMIT 1 DownloadRepository Exists (0.1ms) SELECT 1 AS one FROM `download_repositories` WHERE `download_repositories`.`repository_id` = 408379 LIMIT 1 Using one subselect gives you one access into the repositories index. p=Project.find_by_name('openSUSE:Tools') irb(main):022:0> Benchmark.measure { 100.times { p.has_remote_repositories_old? } } => real=2.6102131991647184 irb(main):023:0> Benchmark.measure { 100.times { p.has_remote_repositories? } } => real=0.0647597061470151 Commit: f47ecabbb3ee7fd51eb9e4a6536ab6c799d330a3 https://github.com/openSUSE/open-build-service/commit/f47ecabbb3ee7fd51eb9e4... Author: Stephan Kulow <stephan@kulow.org> Date: 2018-12-20 (Thu, 20 Dec 2018) Changed paths: M src/api/app/models/project.rb Log Message: ----------- Merge pull request #6682 from coolo/avoid_sql3 Avoid N+1 queries in update policy Compare: https://github.com/openSUSE/open-build-service/compare/708540bb012a...f47eca... **NOTE:** This service has been marked for deprecation: https://developer.github.com/changes/2018-04-25-github-services-deprecation/ Functionality will be removed from GitHub.com on January 31st, 2019.
participants (1)
-
Stephan Kulow