Refactor how expired namespaces are removed from index
What does this MR do and why?
Related to #439769 (closed)
This MR adjusts what qualifies as an "expired" namespace for removal from advanced search. The previous logic was missing removing trials that are null and as a result there are a good number of namespaces that need to be removed from the index.
Due to the large number (see internal comment, I've added a limit of 1000 namespaces that can be removed in one run. The cronworker runs once per day and I think it's ok to remove things slowly (they have been in the index this long so a slow removal will be safer)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
N/A this is changes to a cron job
How to set up and validate locally
- create 2
ElasticsearchIndexedNamespacerecords with default plan subscriptionsplan = Plan.default Group.last(2).each do |g| GitlabSubscription.create(namespace_id: g.id, hosted_plan_id: plan.id) ElasticsearchIndexedNamespace.create(namespace_id: g.id) end - create 2
ElasticsearchIndexedNamespacerecords withbronzeplan subscriptionsplan = Plan.find_by_name('bronze') groups = Group.first(2) # one with no expiration GitlabSubscription.create(namespace_id: groups.first.id, hosted_plan_id: plan.id) ElasticsearchIndexedNamespace.create(namespace_id: groups.first.id) # one with an expired subscription expiration GitlabSubscription.create(namespace_id: groups.second.id, hosted_plan_id: plan.id, start_date: 1.months.ago, end_date: 2.months.ago) ElasticsearchIndexedNamespace.create(namespace_id: groups.second.id) - verify that there are 4 records in
ElasticsearchIndexedNamespacetableElasticsearchIndexedNamespace.count - run the destroy command
ElasticsearchIndexedNamespace.destroy_namespaces_with_expired_subscriptions! - verify that there is 1 record in
ElasticsearchIndexedNamespacetableElasticsearchIndexedNamespace.count
Edited by Terri Chu