Add class method to update last_downloaded_at

Context

In Add packages_composer_packages database table (!186126 - merged) we have added the new packages_composer_packages table that will be used for the composer packages in the future.

While working on Foundation: Prepare application code to read fr... (#548761 - closed) that changes the code: write to the old table and read from the new table, it was spotted that we need to change the way how we update the last_downloaded_at column here. The reason is the finder will return the entry from the new table, but we should use the old table for writing.

What does this MR do and why?

Add class method to update last_downloaded_at.

There might be the case when it's needed to invoke the update of last_downloaded_at indirectly: only object's id is known, but no instance is loaded.

References

Foundation: Prepare application code to read fr... (#548761 - closed)

Screenshots or screen recordings

No.

How to set up and validate locally

Verify the changes in the rails console:

# stub file upload
def fixture_file_upload(*args, **kwargs)
  Rack::Test::UploadedFile.new(*args, **kwargs)
end

p = FactoryBot.create(:npm_package)

Packages::Npm::Package.touch_last_downloaded_at(p.id)

p.reload.last_downloaded_at # should return a timestamp

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #548761 (closed)

Edited by Dzmitry (Dima) Meshcharakou

Merge request reports

Loading