mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Temporarily disable populate_db parallelism to support Django 1.6.
We don't really take good advantage of the parallelism anyway (though it is very useful if you want to make 10000 messages, we don't do that often). If we decide we need that functionality, we can figure out what the right way is to do threads with this stuff. (imported from commit 98aa4b54fab6fd437b7c7ac0c3c7e658d2f8cb33)
This commit is contained in:
@@ -11,7 +11,6 @@ from zerver.models import Message, UserProfile, Stream, Recipient, Client, \
|
|||||||
from zerver.lib.actions import do_send_message, set_default_streams, \
|
from zerver.lib.actions import do_send_message, set_default_streams, \
|
||||||
do_activate_user, do_deactivate, do_change_password
|
do_activate_user, do_deactivate, do_change_password
|
||||||
from zerver.lib.parallel import run_parallel
|
from zerver.lib.parallel import run_parallel
|
||||||
from django.db import transaction, connection
|
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from zerver.lib.bulk_create import bulk_create_realms, \
|
from zerver.lib.bulk_create import bulk_create_realms, \
|
||||||
@@ -184,11 +183,9 @@ class Command(BaseCommand):
|
|||||||
if i < options["num_messages"] % threads:
|
if i < options["num_messages"] % threads:
|
||||||
count += 1
|
count += 1
|
||||||
jobs.append((count, personals_pairs, options, self.stdout.write))
|
jobs.append((count, personals_pairs, options, self.stdout.write))
|
||||||
for status, job in run_parallel(send_messages, jobs, threads=threads):
|
|
||||||
pass
|
for job in jobs:
|
||||||
# Get a new database connection, after our parallel jobs
|
send_messages(job)
|
||||||
# closed the original one
|
|
||||||
connection.close()
|
|
||||||
|
|
||||||
if options["delete"]:
|
if options["delete"]:
|
||||||
# Create the "website" and "API" clients; if we don't, the
|
# Create the "website" and "API" clients; if we don't, the
|
||||||
@@ -256,13 +253,11 @@ class Command(BaseCommand):
|
|||||||
create_users(realms, internal_zulip_users_nosubs, bot=True)
|
create_users(realms, internal_zulip_users_nosubs, bot=True)
|
||||||
|
|
||||||
# Mark all messages as read
|
# Mark all messages as read
|
||||||
with transaction.commit_on_success():
|
|
||||||
UserMessage.objects.all().update(flags=UserMessage.flags.read)
|
UserMessage.objects.all().update(flags=UserMessage.flags.read)
|
||||||
|
|
||||||
self.stdout.write("Successfully populated test database.\n")
|
self.stdout.write("Successfully populated test database.\n")
|
||||||
if options["replay_old_messages"]:
|
if options["replay_old_messages"]:
|
||||||
restore_saved_messages()
|
restore_saved_messages()
|
||||||
connection.close()
|
|
||||||
|
|
||||||
recipient_hash = {}
|
recipient_hash = {}
|
||||||
def get_recipient_by_id(rid):
|
def get_recipient_by_id(rid):
|
||||||
@@ -677,7 +672,6 @@ def restore_saved_messages():
|
|||||||
active=pending_subs[pending_sub])
|
active=pending_subs[pending_sub])
|
||||||
subscriptions_to_add.append(s)
|
subscriptions_to_add.append(s)
|
||||||
Subscription.objects.bulk_create(subscriptions_to_add)
|
Subscription.objects.bulk_create(subscriptions_to_add)
|
||||||
with transaction.commit_on_success():
|
|
||||||
for (sub, active) in subscriptions_to_change:
|
for (sub, active) in subscriptions_to_change:
|
||||||
current_subs_obj[sub].active = active
|
current_subs_obj[sub].active = active
|
||||||
current_subs_obj[sub].save(update_fields=["active"])
|
current_subs_obj[sub].save(update_fields=["active"])
|
||||||
@@ -699,7 +693,6 @@ def restore_saved_messages():
|
|||||||
print datetime.datetime.now(), "Filling in user pointers..."
|
print datetime.datetime.now(), "Filling in user pointers..."
|
||||||
|
|
||||||
# Set restored pointers to the very latest messages
|
# Set restored pointers to the very latest messages
|
||||||
with transaction.commit_on_success():
|
|
||||||
for user_profile in UserProfile.objects.all():
|
for user_profile in UserProfile.objects.all():
|
||||||
try:
|
try:
|
||||||
top = UserMessage.objects.filter(
|
top = UserMessage.objects.filter(
|
||||||
@@ -721,9 +714,6 @@ def restore_saved_messages():
|
|||||||
def send_messages(data):
|
def send_messages(data):
|
||||||
(tot_messages, personals_pairs, options, output) = data
|
(tot_messages, personals_pairs, options, output) = data
|
||||||
random.seed(os.getpid())
|
random.seed(os.getpid())
|
||||||
# Close the database connection, so that we get a new one that
|
|
||||||
# isn't shared with the other threads
|
|
||||||
connection.close()
|
|
||||||
texts = file("zilencer/management/commands/test_messages.txt", "r").readlines()
|
texts = file("zilencer/management/commands/test_messages.txt", "r").readlines()
|
||||||
offset = random.randint(0, len(texts))
|
offset = random.randint(0, len(texts))
|
||||||
|
|
||||||
@@ -740,7 +730,6 @@ def send_messages(data):
|
|||||||
random_max = 1000000
|
random_max = 1000000
|
||||||
recipients = {}
|
recipients = {}
|
||||||
while num_messages < tot_messages:
|
while num_messages < tot_messages:
|
||||||
with transaction.commit_on_success():
|
|
||||||
saved_data = ''
|
saved_data = ''
|
||||||
message = Message()
|
message = Message()
|
||||||
message.sending_client = get_client('populate_db')
|
message.sending_client = get_client('populate_db')
|
||||||
@@ -795,5 +784,4 @@ def send_messages(data):
|
|||||||
|
|
||||||
recipients[num_messages] = [message_type, message.recipient.id, saved_data]
|
recipients[num_messages] = [message_type, message.recipient.id, saved_data]
|
||||||
num_messages += 1
|
num_messages += 1
|
||||||
connection.close()
|
|
||||||
return tot_messages
|
return tot_messages
|
||||||
|
|||||||
Reference in New Issue
Block a user