Skip to content

TICKET-599: Use pluck and remove unnecessary ActiveRecord object instantiations#7897

Open
Naragod wants to merge 4 commits intomasterfrom
TICKET-599_decrease_admin_user_page_load_time
Open

TICKET-599: Use pluck and remove unnecessary ActiveRecord object instantiations#7897
Naragod wants to merge 4 commits intomasterfrom
TICKET-599_decrease_admin_user_page_load_time

Conversation

@Naragod
Copy link
Copy Markdown
Contributor

@Naragod Naragod commented Apr 2, 2026

Proposed Changes

🐛 Bug fix replace to_json with pluck and prevent unnecessary ActiveRecord object instantiations from being created in memory.

The original code was:

  1. SELECT * FROM users -> 14 columns from DB
  2. Build 14,565 User objects -> Ruby heap allocations, callbacks
  3. to_json(only: 7_fields) -> serialize, discard 7 columns

visible_users.order(:created_at).to_json(only: DEFAULT_FIELDS)

The new code is:

  1. SELECT id, user_name, ... FROM users -> 7 columns from DB
  2. Returns arrays of raw values -> no objects, no callbacks
  3. Zip into hashes, serialize to JSON

rows = visible_users.order(:created_at).pluck(*DEFAULT_FIELDS)
rows.map { |r| DEFAULT_FIELDS.zip(r).to_h }

Screenshots of your changes (if applicable)
Associated documentation repository pull request (if applicable)

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue) X
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

@Naragod Naragod requested a review from donny-wong April 2, 2026 19:18
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 2, 2026

Coverage Report for CI Build 24058740316

Coverage increased (+0.001%) to 91.71%

Details

  • Coverage increased (+0.001%) from the base build.
  • Patch coverage: 6 of 6 lines across 2 files are fully covered (100%).
  • 11 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

11 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
app/controllers/api/users_controller.rb 11 78.33%

Coverage Stats

Coverage Status
Relevant Lines: 48456
Covered Lines: 45180
Line Coverage: 93.24%
Relevant Branches: 1844
Covered Branches: 950
Branch Coverage: 51.52%
Branches in Coverage %: Yes
Coverage Strength: 130.71 hits per line

💛 - Coveralls

@Naragod Naragod force-pushed the TICKET-599_decrease_admin_user_page_load_time branch from 880c625 to 08a9736 Compare April 7, 2026 00:52
@donny-wong donny-wong linked an issue Apr 9, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

@donny-wong donny-wong left a comment

Choose a reason for hiding this comment

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

Very good @Naragod !

@donny-wong donny-wong requested a review from david-yz-liu April 9, 2026 20:25
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.

Loading user list on Admin UI is very slow

4 participants