Skip to content

Commit

Permalink
fix: fixture order
Browse files Browse the repository at this point in the history
  • Loading branch information
X committed Apr 10, 2024
1 parent d1e593e commit 9a79dc4
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/backend/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,38 +80,6 @@ fn post_upgrade() {

#[allow(clippy::all)]
fn sync_post_upgrade_fixtures() {
// Fills new data structures with data
mutate(|state| {
// create indexes for all tags of active subscribers
state.tag_indexes = state.users.values().fold(HashMap::new(), |mut acc, user| {
for tag in user.feeds.iter().flatten() {
let index = acc.entry(tag.clone()).or_default();
index.subscribers += 1;
}
acc
});

// create indexes for all tags
for (post_id, tag) in state
.posts_with_tags
.iter()
.filter_map(|id| Post::get(state, id))
.flat_map(|post| {
post.tags
.iter()
.map(move |tag| (post.id, tag.to_lowercase()))
})
.collect::<Vec<_>>()
.into_iter()
{
let entry = state.tag_indexes.entry(tag.clone()).or_default();
entry.posts.push_front(post_id);
while entry.posts.len() > 1000 {
entry.posts.pop_back();
}
}
});

// Restore features and corrupted posts
#[cfg(not(any(feature = "dev", feature = "staging")))]
{
Expand Down Expand Up @@ -150,6 +118,38 @@ fn sync_post_upgrade_fixtures() {
.for_each(|(author, post_id)| features::create_feature(author, post_id).unwrap());
}

// Fills new data structures with data
mutate(|state| {
// create indexes for all tags of active subscribers
state.tag_indexes = state.users.values().fold(HashMap::new(), |mut acc, user| {
for tag in user.feeds.iter().flatten() {
let index = acc.entry(tag.clone()).or_default();
index.subscribers += 1;
}
acc
});

// create indexes for all tags
for (post_id, tag) in state
.posts_with_tags
.iter()
.filter_map(|id| Post::get(state, id))
.flat_map(|post| {
post.tags
.iter()
.map(move |tag| (post.id, tag.to_lowercase()))
})
.collect::<Vec<_>>()
.into_iter()
{
let entry = state.tag_indexes.entry(tag.clone()).or_default();
entry.posts.push_front(post_id);
while entry.posts.len() > 1000 {
entry.posts.pop_back();
}
}
});

// Compensate for the executed by failed proposal #/post/1159871
mutate(|state| {
if let Some(realm) = state.realms.get_mut("RUGANG") {
Expand Down

0 comments on commit 9a79dc4

Please sign in to comment.