Skip to content

Remove order clause from scopes#19508

Open
eduardoj wants to merge 4 commits intoopenSUSE:masterfrom
eduardoj:refactoring/remove_order_from_scopes
Open

Remove order clause from scopes#19508
eduardoj wants to merge 4 commits intoopenSUSE:masterfrom
eduardoj:refactoring/remove_order_from_scopes

Conversation

@eduardoj
Copy link
Copy Markdown
Member

@eduardoj eduardoj commented Apr 1, 2026

No description provided.

@eduardoj eduardoj changed the title Rremove order from scopes Rremove order clause from scopes Apr 1, 2026
@github-actions github-actions bot added the Frontend Things related to the OBS RoR app label Apr 1, 2026
@eduardoj eduardoj marked this pull request as ready for review April 1, 2026 16:47
Copilot AI review requested due to automatic review settings April 1, 2026 16:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes implicit order(...) clauses from several ActiveRecord scopes and updates call sites to apply ordering explicitly where needed, aiming to avoid “hidden” ordering behavior in model scopes.

Changes:

  • Removed ordering from StatusMessage scopes (including deleting newest) and added explicit order(created_at: :desc) at updated call sites.
  • Removed Comment.newest_first and replaced its usage with explicit ordering.
  • Removed Package.order_by_name and updated the one call site to no longer use it.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/api/app/models/status_message.rb Removes ordering from announcements scope; adds explicit ordering in latest_for_current_user.
src/api/app/models/package.rb Removes order_by_name scope.
src/api/app/models/comment.rb Removes newest_first scope.
src/api/app/controllers/webui/users_controller.rb Replaces newest_first scope usage with explicit order(created_at: :desc).
src/api/app/controllers/webui/status_messages_controller.rb Replaces newest scope usage with explicit order(created_at: :desc).
src/api/app/controllers/webui/projects/rebuild_times_controller.rb Stops using order_by_name when building package lists.
src/api/app/controllers/webui/main_controller.rb Replaces newest scope usage with explicit order(created_at: :desc).
src/api/app/controllers/webui/feeds_controller.rb Replaces newest scope usage with explicit order(created_at: :desc).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@eduardoj eduardoj changed the title Rremove order clause from scopes Remove order clause from scopes Apr 1, 2026

validates :severity, :message, presence: true

scope :announcements, -> { order(created_at: :desc).where(severity: 'announcement') }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@eduardoj I think you need to add order(created_at: :desc) here as well

@status_messages = StatusMessage.announcements
after removing it from the scope

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@krauselukas same issue reported by Copilot, better solution. I added the missing order clause. Thanks!

eduardoj added 2 commits April 8, 2026 16:50
It is used only once, in a query where the order of the packages
returned doesn't matter.
It is used only once. It can be replaced with the `order` clause.
@eduardoj eduardoj force-pushed the refactoring/remove_order_from_scopes branch from 7b87103 to 0a68033 Compare April 8, 2026 14:50
eduardoj added 2 commits April 8, 2026 16:51
It contains only an `order` clause. It can be easily replaced by the
`order` clause.

The `newest` name is also misleading: the scope doesn't return the
newest record.
@eduardoj eduardoj force-pushed the refactoring/remove_order_from_scopes branch from 0a68033 to 1ffa05e Compare April 8, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Frontend Things related to the OBS RoR app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants