From c46149efcb2ed73cd73dd37eea0076912e5d0fb7 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 15 May 2018 17:10:39 -0700 Subject: [PATCH] migrate: Remove obsolete act_on_message_ranges. This has a cool structure, but it's written against the long-dead South API, and we can always pull it out of the Git history if we want to use this approach in the future. --- tools/test-backend | 1 - zerver/lib/migrate.py | 40 ---------------------------------------- 2 files changed, 41 deletions(-) diff --git a/tools/test-backend b/tools/test-backend index 2e84ebd9a1..876ae68819 100755 --- a/tools/test-backend +++ b/tools/test-backend @@ -75,7 +75,6 @@ not_yet_fully_covered = { 'zerver/lib/html_diff.py', 'zerver/lib/import_realm.py', 'zerver/lib/logging_util.py', - 'zerver/lib/migrate.py', 'zerver/lib/outgoing_webhook.py', 'zerver/lib/parallel.py', 'zerver/lib/profile.py', diff --git a/zerver/lib/migrate.py b/zerver/lib/migrate.py index e753599ab2..46c4bdc5f4 100644 --- a/zerver/lib/migrate.py +++ b/zerver/lib/migrate.py @@ -25,43 +25,3 @@ def create_index_if_not_exist(index_name: str, table_name: str, column_string: s END$$; ''' % (index_name, index_name, table_name, column_string, where_clause) return stmt - -def act_on_message_ranges(db: Any, - orm: Dict[str, Any], - tasks: List[Tuple[Callable[[QuerySet], QuerySet], Callable[[QuerySet], None]]], - batch_size: int=5000, - sleep: float=0.5) -> None: - # tasks should be an array of (filterer, action) tuples - # where filterer is a function that returns a filtered QuerySet - # and action is a function that acts on a QuerySet - - all_objects = orm['zerver.Message'].objects - - try: - min_id = all_objects.all().order_by('id')[0].id - except IndexError: - print('There is no work to do') - return - - max_id = all_objects.all().order_by('-id')[0].id - print("max_id = %d" % (max_id,)) - overhead = int((max_id + 1 - min_id) / batch_size * sleep / 60) - print("Expect this to take at least %d minutes, just due to sleeps alone." % (overhead,)) - - while min_id <= max_id: - lower = min_id - upper = min_id + batch_size - 1 - if upper > max_id: - upper = max_id - - print('%s about to update range %s to %s' % (time.asctime(), lower, upper)) - - db.start_transaction() - for filterer, action in tasks: - objects = all_objects.filter(id__range=(lower, upper)) - targets = filterer(objects) - action(targets) - db.commit_transaction() - - min_id = upper + 1 - time.sleep(sleep)