Skip to content

Chore(optimisation): rewrite BillableMetricFilters::RefreshDraftInvocies query to get rid of the joins - #6071

Draft
annvelents wants to merge 1 commit into
mainfrom
fix/optimise-bm-refresh-drafts
Draft

Chore(optimisation): rewrite BillableMetricFilters::RefreshDraftInvocies query to get rid of the joins#6071
annvelents wants to merge 1 commit into
mainfrom
fix/optimise-bm-refresh-drafts

Conversation

@annvelents

Copy link
Copy Markdown
Contributor

Context

The job of refreshing invoices fails with timeout, having a separate query + subquery will help us not to join all the tables together

.distinct
.in_batches do |batch|
.where(id: InvoiceSubscription
.where(subscription_id: Subscription.where(plan_id: plan_ids).select(:id))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we filter on active sub only?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, no
because if subscription is terminating / upgrading, we can generate an invoice that will be draft, when the subscription is already terminated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants