mirror of https://github.com/zulip/zulip.git
bulk_insert_ums: Use psycopg2.extras.execute_values.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
5839fdf963
commit
6649c8e35f
|
@ -11,6 +11,8 @@ from django.utils.html import escape
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
|
from psycopg2.extras import execute_values
|
||||||
|
from psycopg2.sql import SQL
|
||||||
from analytics.lib.counts import COUNT_STATS, do_increment_logging_stat, \
|
from analytics.lib.counts import COUNT_STATS, do_increment_logging_stat, \
|
||||||
RealmCount
|
RealmCount
|
||||||
|
|
||||||
|
@ -1632,18 +1634,18 @@ def bulk_insert_ums(ums: List[UserMessageLite]) -> None:
|
||||||
if not ums:
|
if not ums:
|
||||||
return
|
return
|
||||||
|
|
||||||
vals = ','.join([
|
vals = [
|
||||||
'(%d, %d, %d)' % (um.user_profile_id, um.message_id, um.flags)
|
(um.user_profile_id, um.message_id, um.flags)
|
||||||
for um in ums
|
for um in ums
|
||||||
])
|
]
|
||||||
query = '''
|
query = SQL('''
|
||||||
INSERT into
|
INSERT into
|
||||||
zerver_usermessage (user_profile_id, message_id, flags)
|
zerver_usermessage (user_profile_id, message_id, flags)
|
||||||
VALUES
|
VALUES %s
|
||||||
''' + vals
|
''')
|
||||||
|
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute(query)
|
execute_values(cursor.cursor, query, vals)
|
||||||
|
|
||||||
def do_add_submessage(realm: Realm,
|
def do_add_submessage(realm: Realm,
|
||||||
sender_id: int,
|
sender_id: int,
|
||||||
|
|
Loading…
Reference in New Issue