Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload searchkick import #4697

Merged
merged 2 commits into from May 12, 2024
Merged

Preload searchkick import #4697

merged 2 commits into from May 12, 2024

Conversation

nateberkopec
Copy link
Contributor

Before:

SQL (1.6ms)  SELECT "dependencies"."id" AS t0_r0, "dependencies"."requirements" AS t0_r1, "dependencies"."created_at" AS t0_r2, "dependencies"."updated_at" AS t0_r3, "dependencies"."rubygem_id" AS t0_r4, "dependencies"."version_id" AS t0_r5, "dependencies"."scope" AS t0_r6, "dependencies"."unresolved_name" AS t0_r7, "rubygems"."id" AS t1_r0, "rubygems"."name" AS t1_r1, "rubygems"."created_at" AS t1_r2, "rubygems"."updated_at" AS t1_r3, "rubygems"."indexed" AS t1_r4 FROM "dependencies" LEFT OUTER JOIN "rubygems" ON "rubygems"."id" = "dependencies"."rubygem_id" WHERE "dependencies"."version_id" = 249327 ORDER BY "rubygems"."name" ASC
  ↳ app/models/concerns/rubygem_searchable.rb:34:in `search_data'
  Linkset Load (1.2ms)  SELECT "linksets".* FROM "linksets" WHERE "linksets"."rubygem_id" = 45403 LIMIT 1
  ↳ app/models/links.rb:25:in `initialize'
  GemDownload Load (1.2ms)  SELECT "gem_downloads".* FROM "gem_downloads" WHERE "gem_downloads"."rubygem_id" = 45403 AND "gem_downloads"."version_id" = 0 LIMIT 1
  ↳ app/models/rubygem.rb:201:in `downloads'
  GemDownload Load (1.3ms)  SELECT "gem_downloads".* FROM "gem_downloads" WHERE "gem_downloads"."version_id" = 249327 LIMIT 1
  ↳ app/models/version.rb:296:in `downloads_count'
  Version Load (1.3ms)  SELECT "versions".* FROM "versions" WHERE "versions"."rubygem_id" = 45403
  ↳ app/models/concerns/rubygem_searchable.rb:59:in `search_data'
  Version Load (2.1ms)  SELECT "versions".* FROM "versions" WHERE "versions"."rubygem_id" = 45404 ORDER BY case when "versions".latest AND "versions".platform = 'ruby' then 2 else 1 end desc, case when "versions".latest then "versions".number else NULL end desc, "versions"."id" DESC LIMIT 1
  ↳ app/models/concerns/rubygem_searchable.rb:33:in `search_data'

After:

  SQL (0.5ms)  SELECT "dependencies"."id" AS t0_r0, "dependencies"."requirements" AS t0_r1, "dependencies"."created_at" AS t0_r2, "dependencies"."updated_at" AS t0_r3, "dependencies"."rubygem_id" AS t0_r4, "dependencies"."version_id" AS t0_r5, "dependencies"."scope" AS t0_r6, "dependencies"."unresolved_name" AS t0_r7, "rubygems"."id" AS t1_r0, "rubygems"."name" AS t1_r1, "rubygems"."created_at" AS t1_r2, "rubygems"."updated_at" AS t1_r3, "rubygems"."indexed" AS t1_r4 FROM "dependencies" LEFT OUTER JOIN "rubygems" ON "rubygems"."id" = "dependencies"."rubygem_id" WHERE "dependencies"."version_id" = 201160 ORDER BY "rubygems"."name" ASC
  ↳ app/models/concerns/rubygem_searchable.rb:36:in `search_data'
  GemDownload Load (0.3ms)  SELECT "gem_downloads".* FROM "gem_downloads" WHERE "gem_downloads"."version_id" = 201160 LIMIT 1
  ↳ app/models/version.rb:296:in `downloads_count'

I tried adding latest_version: [:gem_download, :dependencies] but that doesn't seem to work. Not sure why.

Prevents N+1 during searchkick import
Copy link

codecov bot commented May 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.11%. Comparing base (5e5ba73) to head (bee0662).
Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4697   +/-   ##
=======================================
  Coverage   97.11%   97.11%           
=======================================
  Files         393      393           
  Lines        8324     8325    +1     
=======================================
+ Hits         8084     8085    +1     
  Misses        240      240           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@simi
Copy link
Member

simi commented May 8, 2024

ℹ️ rubocop complains about trailing white-space. Any idea what's the impact? Seems this is used mostly for development (which is no excuse to not use most effective way). In production, there is usually used parallel reindex and that load models again.

@simi
Copy link
Member

simi commented May 12, 2024

ℹ️ I have fixed Rubocop issue. Thanks for the PR!

@simi simi merged commit 43ac749 into rubygems:master May 12, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants