From 5fac9e5d9459f381376b3f7d3e604f44caac6b8d Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Thu, 3 Jun 2021 13:31:01 +0200 Subject: [PATCH] LiveSync: Add setting to disable category runs --- livesync/indico_livesync/base.py | 12 +++++++----- livesync/indico_livesync/plugin.py | 8 +++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/livesync/indico_livesync/base.py b/livesync/indico_livesync/base.py index fbd45bb..6274c45 100644 --- a/livesync/indico_livesync/base.py +++ b/livesync/indico_livesync/base.py @@ -22,7 +22,7 @@ from indico.util.decorators import classproperty from indico_livesync.forms import AgentForm from indico_livesync.initial import (apply_acl_entry_strategy, query_attachments, query_contributions, query_events, query_notes, query_subcontributions) -from indico_livesync.models.queue import LiveSyncQueueEntry +from indico_livesync.models.queue import EntryType, LiveSyncQueueEntry from indico_livesync.plugin import LiveSyncPlugin @@ -97,11 +97,13 @@ class LiveSyncBackendBase: return True, None return False, 'initial export not performed' - def fetch_records(self, count=None): + def fetch_records(self): query = (self.agent.queue - .filter_by(processed=False) - .order_by(LiveSyncQueueEntry.timestamp) - .limit(count)) + .filter(~LiveSyncQueueEntry.processed) + .order_by(LiveSyncQueueEntry.timestamp)) + if LiveSyncPlugin.settings.get('skip_category_changes'): + LiveSyncPlugin.logger.warning('Category changes are currently being skipped') + query = query.filter(LiveSyncQueueEntry.type != EntryType.category) return query.all() def update_last_run(self): diff --git a/livesync/indico_livesync/plugin.py b/livesync/indico_livesync/plugin.py index b2b8e82..dd7ca68 100644 --- a/livesync/indico_livesync/plugin.py +++ b/livesync/indico_livesync/plugin.py @@ -35,6 +35,11 @@ class SettingsForm(IndicoForm): "subcategories are excluded.")) disable_queue_runs = BooleanField(_('Disable queue runs'), widget=SwitchWidget(), description=_('Disable all scheduled queue runs.')) + skip_category_changes = BooleanField(_('Skip category changes'), widget=SwitchWidget(), + description=_('Skip category changes when processing the queue. This can be ' + 'useful in large instances when there are significant changes ' + 'to large categories in order to avoid processing those ' + 'immediately.')) class LiveSyncPlugin(IndicoPlugin): @@ -47,7 +52,8 @@ class LiveSyncPlugin(IndicoPlugin): settings_form = SettingsForm default_settings = {'excluded_categories': [], 'queue_entry_ttl': 0, - 'disable_queue_runs': False} + 'disable_queue_runs': False, + 'skip_category_changes': False} category = PluginCategory.synchronization def init(self):