Conversation
…ed performance and clarity - Updated the ContainersController to include contest instances in the retrieval of contest descriptions, optimizing data loading and reducing N+1 query issues. - Enhanced the ContestDescriptionsHelper to simplify the logic for determining active contest instances and counting entries, improving code readability and maintainability. These changes enhance the efficiency of contest descriptions handling and improve the overall user experience.
Refactor contest descriptions retrieval and helper methods for improv…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves how contest descriptions and their related data are loaded and displayed, focusing on optimizing database queries and making entry counts more accurate. The main changes involve eager loading related models to reduce N+1 queries, refining how active contest descriptions are selected, and improving the logic for counting entries.
Performance and Query Optimization:
ContainersController#show, contest descriptions are now eager-loaded with theircontest_instancesand associatedentriesto minimize N+1 query issues when displaying contest details.Logic Improvements:
select(&:active?)on already loaded descriptions, ensuring only the relevant, active ones are processed.ContestDescriptionsHelper, the method for finding the first active contest instance now usesdetect(&:active?)for efficiency and clarity.reject(&:deleted).sizeinstead of a database query, ensuring only non-deleted entries are counted and improving consistency with in-memory objects.select(&:active?)rather than a database query, aligning with the eager-loaded data and reducing redundant queries.