Skip to content

Commit

Permalink
Merge pull request #5155 from bgeuken/refactor_binary_release
Browse files Browse the repository at this point in the history
Refactor binary release
  • Loading branch information
bgeuken committed Jun 19, 2018
2 parents 2403194 + c6642ca commit d8da9e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/api/app/models/binary_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ def self.update_binary_releases_via_json(repository, json, time = Time.now)
obsolete_time: nil,
modify_time: nil }
# check for existing entry
existing = oldlist.where(hash)
Rails.logger.info "ERROR: multiple matches, cleaning up: #{existing.inspect}" if existing.count > 1
matching_binaries = oldlist.where(hash)
Rails.logger.info "ERROR: multiple matches, cleaning up: #{matching_binaries.inspect}" if matching_binaries.exists?
# double definition means broken DB entries
existing.offset(1).destroy_all
matching_binaries.offset(1).destroy_all

# compare with existing entry
if existing.count == 1
entry = existing.first
entry = matching_binaries.first

if entry
if entry.indentical_to?(binary)
# same binary, don't touch
processed_item[entry.id] = true
Expand Down Expand Up @@ -181,12 +182,14 @@ def reset_cache
Rails.cache.delete("xml_binary_release_#{cache_key}")
end

# rubocop:disable Style/DateTime
def indentical_to?(binary_hash)
binary_disturl == binary_hash['disturl'] &&
binary_supportstatus == binary_hash['supportstatus'] &&
binary_buildtime &&
binary_buildtimeto.datetime.utc == ::Time.at(binary['buildtime'].to_i).to_datetime.utc
binary_buildtime.to_datetime.utc == DateTime.strptime(binary['buildtime'].to_s, '%s').utc
end
# rubocop:enable Style/DateTime
#### Alias of methods
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
let(:user) { create(:confirmed_user, login: 'tom') }
let(:project) { user.home_project }
let(:remote_project) { create(:remote_project) }

describe 'GET #show' do
context 'when the home project exist' do
before do
Expand Down

0 comments on commit d8da9e5

Please sign in to comment.