Skip to content
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

refactor: AssignmentRule.apply #26371

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

gavindsouza
Copy link
Collaborator

@gavindsouza gavindsouza commented May 7, 2024

Changes

  • Flush all notifications after commit
    • Avoid ghost notifications sent in case of rollback
    • Bulk job for generating all notifications in a single request/job (perf)
  • Remove outdated DDL query triggers for _assign in tables
  • Cleaner AssignmentRule logic flows / Use early returns and caches
  • Add typing hints to AssignTo APIs

Enqueue notifications in bulk rather than individually.
@github-actions github-actions bot added the add-test-cases Add test case to validate fix or enhancement label May 7, 2024
 - Add typing hints to APIs
 - Pass doc as kwarg in assign_to.add to bypass re-fetching
 - Remove redundant code blocks (add_column _assign, extra error
   handling)
 - Use caches whenever available, and less expensive condition eval
   order
@gavindsouza gavindsouza removed the add-test-cases Add test case to validate fix or enhancement label May 13, 2024
@gavindsouza gavindsouza marked this pull request as ready for review May 13, 2024 14:57
@gavindsouza gavindsouza requested a review from a team as a code owner May 13, 2024 14:57
@gavindsouza gavindsouza requested review from ankush and removed request for a team May 13, 2024 14:57
@@ -292,6 +292,7 @@ def init(site: str, sites_path: str = ".", new_site: bool = False, force=False)
local.role_permissions = {}
local.valid_columns = {}
local.new_doc_templates = {}
local.system_notifications_queue = []
Copy link
Member

Choose a reason for hiding this comment

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

can't this just be part of enqueue to flush after commit?

It implements same exact behavior:

  • Queue till commit
  • flush after commit
  • clear queue in case of rollback or no commit

make_notification_log(doc, users)
else:
frappe.local.system_notifications_queue.append((doc, users))
if flush_system_notifications not in frappe.db.after_commit._functions:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if flush_system_notifications not in frappe.db.after_commit._functions:
if not frappe.local.system_notifications_queue:

Can do this instead of relying on internal attribute. Line will have to move up before append.

Copy link
Member

Choose a reason for hiding this comment

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

This pattern is very common though, maybe we should have deduplicate or once flag on callback manager 😄

@gavindsouza gavindsouza marked this pull request as draft May 15, 2024 16:46
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.

None yet

2 participants