Skip to content

Tag selection box is very slow to load in development mode #2193

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

Open
fbacall opened this issue Apr 29, 2025 · 0 comments
Open

Tag selection box is very slow to load in development mode #2193

fbacall opened this issue Apr 29, 2025 · 0 comments

Comments

@fbacall
Copy link
Contributor

fbacall commented Apr 29, 2025

Adds 5 seconds to page load with 3k SQL queries for me:
Rendering: tags/_select_tags.html.erb 5273.2 +3441.8 3390 sql 317.9

Could be cut down by doing the count in the SQL query:

class Annotation < ApplicationRecord
...
  belongs_to :text_value, -> { where(annotations: { value_type: 'TextValue' }) }, foreign_key: :value_id
...
end


suggested_tags = Annotation.with_attribute_name(type)
  .joins(:text_value)
  .select('text_values.text', 'count(value_id) AS tag_count')
  .group(:value_id).reorder('tag_count desc').limit(suggested_limit)

Before:
Image

After:
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant