Esempio n. 1
0
 def create_newsfeed(self, user, tweet):
     if GateKeeper.is_switch_on('switch_newsfeed_to_hbase'):
         created_at = tweet.timestamp
     else:
         created_at = tweet.created_at
     return NewsFeedService.create(user_id=user.id,
                                   tweet_id=tweet.id,
                                   created_at=created_at)
Esempio n. 2
0
 def create_newsfeed(self, user, tweet):
     # 默认ORM created_at:  2021-11-11 11:11:11.123456 iso format
     # HBaseModel: timestamp format: 16位int
     # 兼容 iso 格式和 int 格式的时间戳
     if GateKeeper.is_switch_on('switch_newsfeed_to_hbase'):
         created_at = tweet.timestamp
     else:
         created_at = tweet.created_at
     return NewsFeedService.create(user_id=user.id,
                                   tweet_id=tweet.id,
                                   created_at=created_at)
Esempio n. 3
0
def fanout_newsfeeds_main_task(tweet_id, created_at, tweet_user_id):
    # import 写在里面避免循环依赖
    from newsfeeds.services import NewsFeedService

    # 将推给自己的 Newsfeed 率先创建,确保自己能最快看到
    NewsFeedService.create(
        user_id=tweet_user_id,
        tweet_id=tweet_id,
        created_at=created_at,
    )

    # 获得所有的 follower ids,按照 batch size 拆分开
    follower_ids = FriendshipService.get_follower_ids(tweet_user_id)
    index = 0
    while index < len(follower_ids):
        batch_ids = follower_ids[index: index + FANOUT_BATCH_SIZE]
        fanout_newsfeeds_batch_task.delay(tweet_id, created_at, batch_ids)
        index += FANOUT_BATCH_SIZE

    return '{} newsfeeds going to fanout, {} batches created.'.format(
        len(follower_ids),
        (len(follower_ids) - 1) // FANOUT_BATCH_SIZE + 1,
    )
Esempio n. 4
0
def fanout_newsfeeds_main_task(tweet_id, created_at, tweet_user_id):
    # import to prevent cycle dependence
    from newsfeeds.services import NewsFeedService

    # first create my own neesfeed
    # NewsFeed.objects.create(user_id=tweet_user_id, tweet_id=tweet_id)
    NewsFeedService.create(
        user_id=tweet_user_id,
        tweet_id=tweet_id,
        created_at=created_at,
    )

    # get all follower ids, fanout in batch
    follower_ids = FriendshipService.get_follower_ids(tweet_user_id)
    index = 0
    while index < len(follower_ids):
        batch_ids = follower_ids[index:index + FANOUT_BATCH_SIZE]
        fanout_newsfeeds_batch_task.delay(tweet_id, created_at, batch_ids)
        index += FANOUT_BATCH_SIZE

    return '{} newsfeeds going to fanout, {} batches created.'.format(
        len(follower_ids),
        (len(follower_ids) - 1) // FANOUT_BATCH_SIZE + 1,
    )
Esempio n. 5
0
def fanout_newsfeeds_main_task(tweet_id, created_at, tweet_user_id):
    # we first create the newsfeed for the publisher, so that user can see the post
    # import 写在里面避免循环依赖
    from newsfeeds.services import NewsFeedService

    # 将推给自己的 Newsfeed 率先创建,确保自己能最快看到
    NewsFeedService.create(
        user_id=tweet_user_id,
        tweet_id=tweet_id,
        created_at=created_at,
    )

    # retrieve all the follower id, and split into batches
    follower_ids = FriendshipService.get_follower_ids(tweet_user_id)
    index = 0
    while index < len(follower_ids):
        batch_ids = follower_ids[index: index + FANOUT_BATCH_SIZE]
        fanout_newsfeeds_batch_task.delay(tweet_id, created_at, batch_ids)
        index += FANOUT_BATCH_SIZE

    return '{} newsfeeds going to fanout, {} batches created.'.format(
        len(follower_ids),
        (len(follower_ids) - 1) // FANOUT_BATCH_SIZE + 1,
    )