-
Notifications
You must be signed in to change notification settings - Fork 1
perf: increase job concurrency, add channel routing and identity keys #151
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
Open
kneckinator
wants to merge
4
commits into
19.0
Choose a base branch
from
worktree-perf+phase9-concurrency
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7b67c1a
perf: bulk membership creation with INSERT ON CONFLICT DO NOTHING
kneckinator 5f8bf9b
fix: include enrollment_date in bulk SQL insert, hoist Date.today()
kneckinator 1c16e0c
perf: add canary patterns to skip statistics during bulk operations
kneckinator 38bc517
perf: increase job concurrency, add channel routing and identity keys
kneckinator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -325,8 +325,8 @@ def mark_import_as_done(self, cycle, msg): | |||||
| cycle.locked_reason = None | ||||||
| cycle.message_post(body=msg) | ||||||
|
|
||||||
| # Update Statistics | ||||||
| cycle._compute_members_count() | ||||||
| # Refresh statistics after bulk operations | ||||||
| cycle.refresh_statistics() | ||||||
|
|
||||||
| def mark_prepare_entitlement_as_done(self, cycle, msg): | ||||||
| """Complete the preparation of entitlements. | ||||||
|
|
@@ -518,10 +518,13 @@ def _check_eligibility_async(self, cycle, beneficiaries_count): | |||||
| jobs = [] | ||||||
| for i in range(0, beneficiaries_count, self.MAX_ROW_JOB_QUEUE): | ||||||
| jobs.append( | ||||||
| self.delayable(channel="cycle")._check_eligibility(cycle, offset=i, limit=self.MAX_ROW_JOB_QUEUE) | ||||||
| self.delayable( | ||||||
| channel="cycle", | ||||||
| identity_key=f"check_elig_{cycle.id}_{i}", | ||||||
| )._check_eligibility(cycle, offset=i, limit=self.MAX_ROW_JOB_QUEUE) | ||||||
| ) | ||||||
| main_job = group(*jobs) | ||||||
| main_job.on_done(self.delayable(channel="cycle").mark_check_eligibility_as_done(cycle)) | ||||||
| main_job.on_done(self.delayable(channel="statistics_refresh").mark_check_eligibility_as_done(cycle)) | ||||||
| main_job.delay() | ||||||
|
|
||||||
| def _check_eligibility(self, cycle, beneficiaries=None, offset=0, limit=None, do_count=False): | ||||||
|
|
@@ -587,10 +590,17 @@ def _prepare_entitlements_async(self, cycle, beneficiaries_count): | |||||
|
|
||||||
| jobs = [] | ||||||
| for i in range(0, beneficiaries_count, self.MAX_ROW_JOB_QUEUE): | ||||||
| jobs.append(self.delayable(channel="cycle")._prepare_entitlements(cycle, i, self.MAX_ROW_JOB_QUEUE)) | ||||||
| jobs.append( | ||||||
| self.delayable( | ||||||
| channel="cycle", | ||||||
| identity_key=f"prepare_ent_{cycle.id}_{i}", | ||||||
| )._prepare_entitlements(cycle, i, self.MAX_ROW_JOB_QUEUE) | ||||||
| ) | ||||||
| main_job = group(*jobs) | ||||||
| main_job.on_done( | ||||||
| self.delayable(channel="cycle").mark_prepare_entitlement_as_done(cycle, _("Entitlement Ready.")) | ||||||
| self.delayable(channel="statistics_refresh").mark_prepare_entitlement_as_done( | ||||||
| cycle, _("Entitlement Ready.") | ||||||
| ) | ||||||
| ) | ||||||
| main_job.delay() | ||||||
|
|
||||||
|
|
@@ -820,40 +830,46 @@ def _add_beneficiaries_async(self, cycle, beneficiaries, state): | |||||
| jobs = [] | ||||||
| for i in range(0, beneficiaries_count, self.MAX_ROW_JOB_QUEUE): | ||||||
| jobs.append( | ||||||
| self.delayable(channel="cycle")._add_beneficiaries( | ||||||
| self.delayable( | ||||||
| channel="cycle", | ||||||
| identity_key=f"add_benef_{cycle.id}_{i}", | ||||||
| )._add_beneficiaries( | ||||||
| cycle, | ||||||
| beneficiaries[i : i + self.MAX_ROW_JOB_QUEUE], | ||||||
| state, | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| main_job = group(*jobs) | ||||||
| main_job.on_done(self.delayable(channel="cycle").mark_import_as_done(cycle, _("Beneficiary import finished."))) | ||||||
| main_job.on_done( | ||||||
| self.delayable(channel="statistics_refresh").mark_import_as_done(cycle, _("Beneficiary import finished.")) | ||||||
| ) | ||||||
| main_job.delay() | ||||||
|
|
||||||
| def _add_beneficiaries(self, cycle, beneficiaries, state="draft", do_count=False): | ||||||
| """Add Beneficiaries | ||||||
|
|
||||||
| :param cycle: Recordset of cycle | ||||||
| :param beneficiaries: Recordset of beneficiaries | ||||||
| :param beneficiaries: List of partner IDs | ||||||
| :param state: String state to be set to beneficiary | ||||||
| :param do_count: Boolean - set to False to not run compute functions | ||||||
| :return: Integer - count of not enrolled members | ||||||
| """ | ||||||
| new_beneficiaries = [] | ||||||
| for r in beneficiaries: | ||||||
| new_beneficiaries.append( | ||||||
| [ | ||||||
| 0, | ||||||
| 0, | ||||||
| { | ||||||
| "partner_id": r, | ||||||
| "enrollment_date": fields.Date.today(), | ||||||
| "state": state, | ||||||
| }, | ||||||
| ] | ||||||
| ) | ||||||
| cycle.update({"cycle_membership_ids": new_beneficiaries}) | ||||||
| :return: Integer - count of inserted members | ||||||
| """ | ||||||
| today = fields.Date.today() | ||||||
| vals_list = [ | ||||||
| { | ||||||
| "partner_id": partner_id, | ||||||
| "cycle_id": cycle.id, | ||||||
| "enrollment_date": today, | ||||||
| "state": state, | ||||||
| } | ||||||
| for partner_id in beneficiaries | ||||||
| ] | ||||||
| self.env["spp.cycle.membership"].bulk_create_memberships(vals_list, skip_duplicates=True) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method
Suggested change
|
||||||
|
|
||||||
| # Raw SQL bypasses the ORM cache — invalidate so subsequent reads | ||||||
| # (e.g. cycle.cycle_membership_ids) reflect the new rows. | ||||||
| cycle.invalidate_recordset(["cycle_membership_ids"]) | ||||||
|
|
||||||
| if do_count: | ||||||
| # Update Statistics | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using raw SQL in Odoo, it is recommended to explicitly use
(now() at time zone 'utc')forcreate_dateandwrite_date. This ensures that the timestamps are stored in UTC regardless of the database session's timezone configuration, adhering to Odoo's standard data storage practices.