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

Fixes #23319 - Add "latest" flag to katello/api/packages #7332

Merged
merged 1 commit into from
Jul 4, 2018
Merged

Fixes #23319 - Add "latest" flag to katello/api/packages #7332

merged 1 commit into from
Jul 4, 2018

Conversation

PaulSD
Copy link
Member

@PaulSD PaulSD commented Apr 20, 2018

This PR was previously dependent on #7324, but #7324 has now been merged, and there are no further dependencies.

@theforeman-bot
Copy link

Issues: #23319

'(CAST(katello_rpms.epoch AS INT) < CAST(katello_rpms2.epoch AS INT) OR ' +
' (CAST(katello_rpms.epoch AS INT) = CAST(katello_rpms2.epoch AS INT) AND ' +
' (katello_rpms.version_sortable < katello_rpms2.version_sortable OR ' +
' (katello_rpms.version_sortable = katello_rpms2.version_sortable AND ' +

Choose a reason for hiding this comment

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

Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.

'katello_rpms.name = katello_rpms2.name AND katello_rpms.arch = katello_rpms2.arch AND ' +
'(CAST(katello_rpms.epoch AS INT) < CAST(katello_rpms2.epoch AS INT) OR ' +
' (CAST(katello_rpms.epoch AS INT) = CAST(katello_rpms2.epoch AS INT) AND ' +
' (katello_rpms.version_sortable < katello_rpms2.version_sortable OR ' +

Choose a reason for hiding this comment

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

Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.

"LEFT OUTER JOIN (#{collection.to_sql}) AS katello_rpms2 ON " +
'katello_rpms.name = katello_rpms2.name AND katello_rpms.arch = katello_rpms2.arch AND ' +
'(CAST(katello_rpms.epoch AS INT) < CAST(katello_rpms2.epoch AS INT) OR ' +
' (CAST(katello_rpms.epoch AS INT) = CAST(katello_rpms2.epoch AS INT) AND ' +

Choose a reason for hiding this comment

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

Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.

collection = collection.joins(
"LEFT OUTER JOIN (#{collection.to_sql}) AS katello_rpms2 ON " +
'katello_rpms.name = katello_rpms2.name AND katello_rpms.arch = katello_rpms2.arch AND ' +
'(CAST(katello_rpms.epoch AS INT) < CAST(katello_rpms2.epoch AS INT) OR ' +

Choose a reason for hiding this comment

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

Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.

# aware of quirks like https://github.com/rails/rails/issues/18379
collection = collection.joins(
"LEFT OUTER JOIN (#{collection.to_sql}) AS katello_rpms2 ON " +
'katello_rpms.name = katello_rpms2.name AND katello_rpms.arch = katello_rpms2.arch AND ' +

Choose a reason for hiding this comment

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

Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.

# `collection.to_sql`, which may be somewhat brittle. For example, be
# aware of quirks like https://github.com/rails/rails/issues/18379
collection = collection.joins(
"LEFT OUTER JOIN (#{collection.to_sql}) AS katello_rpms2 ON " +

Choose a reason for hiding this comment

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

Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.

@PaulSD
Copy link
Member Author

PaulSD commented May 11, 2018

[test katello]

@PaulSD
Copy link
Member Author

PaulSD commented May 21, 2018

@jlsherrill Just making sure this PR is on your radar.

@PaulSD PaulSD changed the title Fixes #23319 - Add latest flag to katello/api/packages Fixes #23319 - Add "latest" flag to katello/api/packages Jun 13, 2018
@PaulSD
Copy link
Member Author

PaulSD commented Jun 14, 2018

ping

' (katello_rpms.version_sortable COLLATE "C" < katello_rpms2.version_sortable COLLATE "C" OR ' \
' (katello_rpms.version_sortable = katello_rpms2.version_sortable AND ' \
' katello_rpms.release_sortable COLLATE "C" < katello_rpms2.release_sortable COLLATE "C"))))'
).where('katello_rpms2.release_sortable IS NULL')
Copy link
Member

Choose a reason for hiding this comment

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

apologies again for the delay. Could we move this to the model? I think a 'latest' class method would make sense. It would look somethign like:

def self.latest
self.joins( "LEFT OUTER JOIN (#{self.to_sql}) ...........
end

Thats really where this belongs.

Also, what about the large amounts of comments below, planning on getting rid of those?

Copy link
Member Author

@PaulSD PaulSD Jun 20, 2018

Choose a reason for hiding this comment

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

Sure, I can try moving this to the model.

As for the comments:
I selected the uncommented implementation based on the current behavior of Rails and the current performance characteristics of PostgreSQL using the current data set in my Satellite installation. It is entirely possible that one of the other commented implementations may work significantly better with a different version of Rails and/or with a different version PostgreSQL and/or with a different database and/or with a different data set.
Since the alternative implementations are significantly different from each other, since their performance characteristics are strongly influenced by unspecified implementation details in other pieces of software, and since they are not particularly obvious or intuitive solutions, I thought it would be a good idea to leave them in there as comments so a future developer could easily swap out the implementation if it becomes advantageous to do so.
I can remove them if you want, but we will loose knowledge about those possible alternatives, and someone may have to re-develop them if something changes and causes the uncommented implementation to behave or perform poorly.

@PaulSD
Copy link
Member Author

PaulSD commented Jun 21, 2018

I've moved latest to the model.

However, note that latest must get an ActiveRecord::Relation object representing a query for all of the other search conditions. self in the model is an ApplicationRecord class, not a Relation, so the suggested example:

def self.latest
  self.joins( "LEFT OUTER JOIN (#{self.to_sql}) ...........
end

doesn't work and instead needs to be something like:

def self.latest(relation)
  relation.joins( "LEFT OUTER JOIN (#{relation.to_sql}) ...........
end

Copy link
Member

@jlsherrill jlsherrill left a comment

Choose a reason for hiding this comment

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

Sorry this review took so long. Thanks for this!

@jlsherrill jlsherrill merged commit 514128c into Katello:master Jul 4, 2018
@PaulSD PaulSD deleted the k6 branch July 4, 2018 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants