Skip to content

Commit

Permalink
WEB-4088 : Add after commit hook to reduce bad image upload to odwb b…
Browse files Browse the repository at this point in the history
…ecause of the transaction speed

New contact hasn't time to go from private to published state ?!
  • Loading branch information
boulch committed Jul 1, 2024
1 parent 8a60ab3 commit f059d51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Changelog
1.2.15 (unreleased)
-------------------

- Nothing changed yet.
- WEB-4088 : Add after commit hook to reduce bad image upload to odwb because of the transaction speed
New contact hasn't time to go from private to published state ?!
[boulch]


1.2.14 (2024-06-28)
Expand Down
12 changes: 9 additions & 3 deletions src/imio/directory/core/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from zope.lifecycleevent.interfaces import IAttributes

import os
import transaction


def set_default_entity_uid(contact):
Expand Down Expand Up @@ -114,15 +115,20 @@ def published_contact_transition(obj, event):
if not IAfterTransitionEvent.providedBy(event):
return
if event.new_state.id == "published":
request = getRequest()
endpoint = OdwbEndpointGet(obj, request)
endpoint.reply()
kwargs = dict(obj=obj)
transaction.get().addAfterCommitHook(send_to_odwb, kws=kwargs)
if event.new_state.id == "private" and event.old_state.id != event.new_state.id:
request = getRequest()
endpoint = OdwbEndpointGet(obj, request)
endpoint.remove()


def send_to_odwb(trans, obj=None):
request = getRequest()
endpoint = OdwbEndpointGet(obj, request)
endpoint.reply()


def mark_current_entity_in_contacts_from_other_entities(obj, event):
changed = False
entities_to_treat = []
Expand Down

0 comments on commit f059d51

Please sign in to comment.