Skip to content

Instantly share code, notes, and snippets.

@vardanator
Created February 18, 2018 20:46
Show Gist options
  • Select an option

  • Save vardanator/0d026eae46eed02ff27c1219f6e91ee9 to your computer and use it in GitHub Desktop.

Select an option

Save vardanator/0d026eae46eed02ff27c1219f6e91ee9 to your computer and use it in GitHub Desktop.
// Warning: a bunch of pseudocode ahead
void RangeInsertIntoTimelines(vector<long> user_ids, long tweet_id)
{
for (auto id : user_ids) {
InsertIntoUserTimeline(id, tweet_id);
}
}
void DeliverATweet(User* author, Tweet* tw)
{
// we assume that 'tw' object is already stored in a database
// 1. Get the list of user's (tweet author's) followers's ids
vector<long> user_followers = GetUserFollowers(author->id);
// 2. Insert tweet into each timeline in parallel
const int CHUNK_SIZE = 4000; // saw this somewhere
for (each CHUNK_SIZE elements in user_followers) {
Thread t = ThreadPool.GetAvailableThread(); // somehow
t.Run(RangeInsertIntoTimelines, current_chunk, tw->id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment