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

Improve performance of ratings in JSON #954

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

reid-rigo
Copy link
Contributor

Description

Case.includes(queries: :ratings) is a heavy operation for large cases.

This optimizes JSON building with a method (Case#doc_ratings_by_query) to load just the needed ratings columns in one shot.

class UpdateQueryUpdatedAtWithRatings < ActiveRecord::Migration[7.1]
def change
execute <<-SQL
UPDATE queries SET updated_at = GREATEST(updated_at, (SELECT MAX(updated_at) FROM ratings WHERE query_id = queries.id))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively a new column could be added like ratings_updated_at

@epugh
Copy link
Member

epugh commented Mar 8, 2024

How about we go through this next Ruby Code Jam??? It hink it could be great!

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.

2 participants