Skip to content

Only track subscription history when applicable

Vijay Hawoldar requested to merge vij-tweak-gitlab-subscription-log into master

What does this MR do and why?

This MR modifies when we create a GitlabSubscriptionHistory record during GitlabSubscription updates.

Previously, we would create a record whenever any attribute changed on the GitlabSubscription, but we only track certain attributes, so we risk potentially creating a bunch of GitlabSubscriptionHistory records unnecessarily.

The list of tracked attributes can be found in GitlabSubscription::TRACKED_ATTRIBUTES - we are only interested in having changes to these attributes stored in the histories table, therefore we only need to create a record when one of those changes.

Refs #393618 (closed)

How to set up and validate locally

  1. Checkout master (i.e. not this MR)
  2. Find a GitlabSubscription record
    gs = GitlabSubscription.last
  3. Confirm history record is created for an untracked attribute change:
    GitlabSubscriptionHistory.where(namespace_id: gs.namespace_id).count
    => 0
    
    gs.update(last_seat_refresh_at: Time.current)
    
    GitlabSubscriptionHistory.where(namespace_id: gs.namespace_id).count
    => 1
  4. Checkout this branch vij-tweak-gitlab-subscription-log
  5. Perform the test above again (remembering to reload! the console) and confirm no history record is created

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vijay Hawoldar

Merge request reports

Loading