From 6a9eaebff29da1ccd3f2ff8953f600d38ab4fba6 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 24 Dec 2019 11:25:25 +0000 Subject: [PATCH] populate_db: Make num_recips calculation more clear. Extracting this calculation makes it easier to hack it when you're trying to load lots of users. We probably want a slightly more realistic calculation here for stress testing. And also fewer rows. But at least now it's a little more clear what it's doing. --- zilencer/management/commands/populate_db.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index c6519eca7a..3247f7850e 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -335,10 +335,14 @@ class Command(BaseCommand): r = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id) subscriptions_list.append((profile, r)) else: + num_streams = len(recipient_streams) + num_users = len(profiles) for i, profile in enumerate(profiles): # Subscribe to some streams. - for type_id in recipient_streams[:int(len(recipient_streams) * - float(i)/len(profiles)) + 1]: + fraction = float(i) / num_users + num_recips = int(num_streams * fraction) + 1 + + for type_id in recipient_streams[:num_recips]: r = Recipient.objects.get(type=Recipient.STREAM, type_id=type_id) subscriptions_list.append((profile, r))