mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
migrate: Add do_batch_update method for running batch updates.
* Refactor pgroonga_0002 migration to use new method.
This commit is contained in:
committed by
Tim Abbott
parent
eddcec5e86
commit
e95f972e24
@@ -3,19 +3,13 @@ from django.db import models, migrations, connection
|
||||
from django.contrib.postgres import operations
|
||||
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
|
||||
from django.db.migrations.state import StateApps
|
||||
from zerver.lib.migrate import do_batch_update
|
||||
|
||||
def rebuild_pgroonga_index(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
||||
BATCH_SIZE = 10000
|
||||
|
||||
Message = apps.get_model("zerver", "Message")
|
||||
message_ids = Message.objects.values_list('id', flat=True)
|
||||
with connection.cursor() as cursor:
|
||||
for i in range(0, len(message_ids), BATCH_SIZE):
|
||||
batch_ids = ', '.join(str(id) for id in message_ids[i:i+BATCH_SIZE])
|
||||
cursor.execute("UPDATE zerver_message SET "
|
||||
"search_pgroonga = "
|
||||
"escape_html(subject) || ' ' || rendered_content "
|
||||
"WHERE id IN (%s)" % (batch_ids,))
|
||||
do_batch_update(cursor, 'zerver_message', ['search_pgroonga'],
|
||||
["escape_html(subject) || ' ' || rendered_content"],
|
||||
escape=False, batch_size=10000)
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
atomic = False
|
||||
|
||||
Reference in New Issue
Block a user