Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed May 1, 2023
1 parent 68ff3e0 commit 81a00de
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,23 +444,39 @@ def s3_query_service
end

def past_snapshots
persisted = UploadSnapshot.where(work: self)
return persisted unless persisted.empty?

built = UploadSnapshot.new(work: self)
[built]
UploadSnapshot.where(work: self)
end

def select_current_snapshots
# Remove the snapshots for S3 file resources which have been deleted
def valid_snapshots
s3_resource_urls = s3_files.map(&:url)
s3_resource_filenames = s3_files.map(&:filename)

# Remove the snapshots for S3 file resources which have been deleted
past_snapshots.select do |snapshot|
s3_resource_urls.include?(snapshot.url) || s3_resource_filenames.include?(snapshot.filename)
end
end

def new_s3_files
s3_files.reject do |s3_file|
UploadSnapshot.find_by(work: self, url: s3_file.url, filename: s3_file.filename)
end
end

def new_snapshots
new_s3_files.map do |s3_file|
UploadSnapshot.new(work: self, url: s3_file.url, filename: s3_file.filename)
end
end

def current_snapshots
valid_snapshots + new_snapshots
end

def invalid_snapshots
current_snapshots - past_snapshots
end

def self.select_matching_snapshots(snapshots:, s3_filename:)
snapshots.select do |snapshot|
# Checking for version substrings
Expand Down Expand Up @@ -488,9 +504,6 @@ def self.select_matching_filename(s3_file:)
# Build or find persisted UploadSnapshot models for this Work
# @return [UploadSnapshot]
def reload_snapshots
persisted = select_current_snapshots
invalid_snapshots = persisted - past_snapshots

work_changes = []

# Remove the existing snapshots and ensure that the WorkActivity is updated
Expand All @@ -505,7 +518,8 @@ def reload_snapshots

s3_files.each do |s3_file|
s3_filename = self.class.select_matching_filename(s3_file: s3_file)
matching_snapshots = self.class.select_matching_snapshots(snapshots: persisted, s3_filename: s3_filename)
matching_snapshots = self.class.select_matching_snapshots(snapshots: current_snapshots, s3_filename: s3_filename)

current_snapshot = matching_snapshots.last

# Compare the checksum values for the updated S3 file and current snapshot
Expand Down

0 comments on commit 81a00de

Please sign in to comment.