Skip to content

fix(billable_metric): Destroy when attached to a lot of charges #3747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025

Conversation

vincent-pochet
Copy link
Collaborator

@vincent-pochet vincent-pochet commented May 27, 2025

Context

Deleting a billable metric attached to a lot of charges and filters may lead to a Timeout error because:

  • The soft deletion of sub-resources is done synchronously
  • It is using discard_all witch is not scalable as it is using a DB call per record...

Description

This PR is moving the filter deletion to a dedicated job and is replacing discard_all calls with update_all(deleted_at:)

@vincent-pochet vincent-pochet force-pushed the fix-large-bm-destroy branch from 8313023 to 9ace42b Compare May 30, 2025 08:22
@vincent-pochet vincent-pochet marked this pull request as ready for review May 30, 2025 08:41
@vincent-pochet vincent-pochet merged commit cd5643e into main May 30, 2025
14 checks passed
@vincent-pochet vincent-pochet deleted the fix-large-bm-destroy branch May 30, 2025 08:46
vincent-pochet added a commit that referenced this pull request Jun 2, 2025
## Context

This PR follows #3747

Deleting a charge in a plan with a large number of override can cause
Timeout error or lead to a memory error on Redis.

The main reasons are:
- The service will enqueue one job per child charge
- In the service, the soft deletion is done using `discard_all` witch is
not scalable as it is using a DB call per record...


## Description

This PR is refactoring the logic to enqueue only one job responsible of
the soft deletion of all child charges.
The filter deletion is also done by replacing `discard_all` calls with
`update_all(deleted_at:)`

Note: The same logic will have to be applied to both update and creation
of child charges
vincent-pochet added a commit that referenced this pull request Jun 2, 2025
## Context

This PR follows #3747 and
#3765

Create a new charge in a plan with a large number of override can cause
Timeout error or lead to a memory error on Redis.

The main reasons is that the service will enqueue one job per child plan


## Description

This PR is refactoring the logic to enqueue only one job responsible of
the creation of all child charges.

Note: The same logic will have to be applied to the update of child
charges
diegocharles pushed a commit that referenced this pull request Jun 2, 2025
## Context

Deleting a billable metric attached to a lot of charges and filters may
lead to a Timeout error because:
- The soft deletion of sub-resources is done synchronously
- It is using `discard_all` witch is not scalable as it is using a DB
call per record...

## Description

This PR is moving the filter deletion to a dedicated job and is
replacing `discard_all` calls with `update_all(deleted_at:)`
diegocharles pushed a commit that referenced this pull request Jun 2, 2025
## Context

This PR follows #3747

Deleting a charge in a plan with a large number of override can cause
Timeout error or lead to a memory error on Redis.

The main reasons are:
- The service will enqueue one job per child charge
- In the service, the soft deletion is done using `discard_all` witch is
not scalable as it is using a DB call per record...


## Description

This PR is refactoring the logic to enqueue only one job responsible of
the soft deletion of all child charges.
The filter deletion is also done by replacing `discard_all` calls with
`update_all(deleted_at:)`

Note: The same logic will have to be applied to both update and creation
of child charges
diegocharles pushed a commit that referenced this pull request Jun 2, 2025
## Context

This PR follows #3747 and
#3765

Create a new charge in a plan with a large number of override can cause
Timeout error or lead to a memory error on Redis.

The main reasons is that the service will enqueue one job per child plan


## Description

This PR is refactoring the logic to enqueue only one job responsible of
the creation of all child charges.

Note: The same logic will have to be applied to the update of child
charges
lovrocolic added a commit that referenced this pull request Jun 9, 2025
## Context

This PR follows:
- #3747
- #3765
- #3767

Updating a charge in a plan with a large number of override can cause
Timeout error or lead to a memory error on Redis.

The main reason is:
- The service will enqueue one job per child charge


## Description

This PR is refactoring the logic to enqueue only one job responsible of
the updates for all child charges.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants