Skip to content
Snippets Groups Projects
Verified Commit 8fcade20 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Delay registration of on_commit hook until first action

parent 4ac097e9
No related branches found
No related tags found
No related merge requests found
...@@ -14,10 +14,7 @@ class CelerySignalProcessor(RealtimeSignalProcessor): ...@@ -14,10 +14,7 @@ class CelerySignalProcessor(RealtimeSignalProcessor):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._queue = [] self._queue = []
self._on_commit_registered = False
def setup(self):
transaction.on_commit(self.run_task)
super().setup()
def handle_save(self, sender, instance, **kwargs): def handle_save(self, sender, instance, **kwargs):
return self.enqueue('update', instance, sender, **kwargs) return self.enqueue('update', instance, sender, **kwargs)
...@@ -55,3 +52,6 @@ class CelerySignalProcessor(RealtimeSignalProcessor): ...@@ -55,3 +52,6 @@ class CelerySignalProcessor(RealtimeSignalProcessor):
if action == 'update' and not index.should_update(instance): if action == 'update' and not index.should_update(instance):
continue continue
self._queue.append((action, get_identifier(instance))) self._queue.append((action, get_identifier(instance)))
if not self._on_commit_registered:
transaction.on_commit(self.run_task)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment