Maven VReg: utilize CounterAttribute concern to increment cached responses downloads count
Context
The downloads_count
column in the virtual_registries_packages_maven_cached_responses
database table needs to be incremented whenever a cached response is downloaded. In #473152 (comment 2117647182), it was agreed on using the CounterAttribute
concern to implement the functionality.
Also, have a downloaded_at
column with the last timestamp. This can quite easily done due to the fact that the CounterAttribute
concern use update_counters
. The rails helper function has us covered as it has a :touch
option where we can pass a (timestamp) column that will be updated along with the counter. Thus, we can override the #update_counters
(instance function) in the cached response model, so that we pass touch: :downloaded_at
to the class function.
⚙️ Technical details
- We need to have
downloads_count
anddownloads_at
on the cache entry record. - Use the
CounterAttribute
to implemented a delayed count update. This way, during theGET
request, these fields are not updated = the entire request will use the replica (read only).
Edited by 🤖 GitLab Bot 🤖