Esempio n. 1
0
    def handle(self, **options):
        engine = get_engine_from_db_alias(options['database'])

        # Call regular syncdb if engine is different from ours
        if engine != 'django_cassandra_engine':
            return super(Command, self).handle(**options)
        else:
            return sync_cassandra.Command().execute(**options)
Esempio n. 2
0
    def handle(self, **options):
        print('Running syncdb for Cassandra')
        sync_cassandra.Command().execute(**options)

        spinner = cycle('|/-\\')

        print('Creating 1000 random users')
        users = []
        user_ids = []
        for i in range(10**3):
            print('\r{} {}'.format(next(spinner), i), end='')
            user = UserModel(name=random_string(title=True))
            user.save()
            users.append(user)
            user_ids.append(user.id)
        print('\r      ', end='\r')

        print('Creating following relationships between these users')
        for i, user in enumerate(users):
            print('\r{} {}'.format(next(spinner), i), end='')
            followers = random.sample(user_ids, random.randrange(50))
            user.following = [uuid for uuid in followers if user.id != uuid]
            user.save()
        print('\r      ', end='\r')

        print('Creating 100k random feed entries')
        random_dates = islice(random_datetime_generator(), 10**4)
        feedids = [uuid_from_time(t) for t in random_dates]
        for i, feedid in enumerate(feedids):
            print('\r{} {}'.format(next(spinner), i), end='')
            entry = FeedEntryModel(userid=random.choice(user_ids),
                                   id=feedid,
                                   comment_count=random.randrange(10))
            entry.save()
        print('\r       ', end='\r')

        print('Creating 5000 random inbox entries')
        types = (CommentedInboxEntryModel, LikeInboxEntryModel,
                 NewFollowerInboxEntryModel)
        random_dates = islice(random_datetime_generator(), 5000)
        inboxids = map(uuid_from_time, random_dates)
        for i, inboxid in enumerate(inboxids):
            print('\r{} {}'.format(next(spinner), i), end='')
            inboxtype = random.choice(types)
            fields = {
                'userid':
                random.choice(user_ids),
                'id':
                inboxid,
                'feedentryid':
                random.choice(feedids),
                'comment_text':
                ' '.join(
                    [random_string() for _ in range(random.randrange(3, 10))]),
                'likerid':
                random.choice(user_ids),
                'followerid':
                random.choice(user_ids),
            }
            entry = inboxtype(**fields)
            entry.save()
        print('\r       ', end='\r')

        print('Creating 1000 random bundles')
        random_dates = islice(random_datetime_generator(), 1000)
        bundleids = map(uuid_from_time, random_dates)
        for i, bundleid in enumerate(bundleids):
            print('\r{} {}'.format(next(spinner), i), end='')
            entrycount = random.randrange(2, 10)
            # pick entrycount unique feedids, not to be used again
            feedids, feedentries = feedids[:-entrycount], feedids[-entrycount:]
            entry = BundleEntryModel(userid=random.choice(user_ids),
                                     id=bundleid,
                                     comment_count=random.randrange(10),
                                     entry_ids=feedentries)
            entry.save()
        print('\r       ', end='\r')