-
-
Notifications
You must be signed in to change notification settings - Fork 927
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
Update linkset homepage from gemspec only after version gets indexed #5249
Draft
segiddins
wants to merge
1
commit into
master
Choose a base branch
from
segiddins/update-linkset-homepage-from-gemspec-only-after-version-gets-indexed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+37
−34
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class SetLinksetHomeJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(version:) | ||
return unless version.latest? && version.indexed? | ||
|
||
gem = RubygemFs.instance.get("gems/#{version.gem_file_name}") | ||
package = Gem::Package.new(StringIO.new(gem)) | ||
homepage = package.spec.homepage | ||
|
||
version.rubygem.linkset ||= Linkset.new | ||
version.rubygem.linkset.update!(home: homepage) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @martinemde this is where we update the linkset |
||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ class Rubygem < ApplicationRecord | |
has_many :versions, dependent: :destroy, validate: false | ||
has_one :latest_version, -> { latest.order(:position) }, class_name: "Version", inverse_of: :rubygem | ||
has_many :web_hooks, dependent: :destroy | ||
has_one :linkset, dependent: :destroy | ||
has_one :linkset, dependent: :destroy, inverse_of: :rubygem | ||
has_one :gem_download, -> { where(version_id: 0) }, inverse_of: :rubygem | ||
has_many :ownership_calls, -> { opened }, dependent: :destroy, inverse_of: :rubygem | ||
has_many :ownership_requests, -> { opened }, dependent: :destroy, inverse_of: :rubygem | ||
|
@@ -273,34 +273,11 @@ def ownership_call | |
ownership_calls.find_by(status: "opened") | ||
end | ||
|
||
def update_versions!(version, spec) | ||
version.update_attributes_from_gem_specification!(spec) | ||
end | ||
|
||
def update_dependencies!(version, spec) | ||
spec.dependencies.each do |dependency| | ||
version.dependencies.create!(gem_dependency: dependency) | ||
rescue ActiveRecord::RecordInvalid => e | ||
# ActiveRecord can't chain a nested error here, so we have to add and reraise | ||
e.record.errors.errors.each do |error| | ||
errors.import(error, attribute: "dependency.#{error.attribute}") | ||
end | ||
raise | ||
end | ||
end | ||
|
||
def update_linkset!(spec) | ||
self.linkset ||= Linkset.new | ||
self.linkset.update_attributes_from_gem_specification!(spec) | ||
self.linkset.save! | ||
end | ||
|
||
def update_attributes_from_gem_specification!(version, spec) | ||
Rubygem.transaction do | ||
save! | ||
update_versions! version, spec | ||
update_dependencies! version, spec | ||
update_linkset! spec if version.reload.latest? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we never update the linkset now. Is that expected? |
||
version.update_attributes_from_gem_specification!(spec) | ||
version.update_dependencies!(spec) | ||
end | ||
end | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only job that redownloads the gem besides the content storage job. Could it just grab this info on push?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now we don't pass anything besides the version itself to the "after write" set of jobs, so I kept in keeping with that