Skip to content

Commit

Permalink
fix: only load reaction status when in view
Browse files Browse the repository at this point in the history
  • Loading branch information
trisuaso committed Nov 18, 2024
1 parent 4a9a7d4 commit b14532a
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 244 deletions.
32 changes: 0 additions & 32 deletions crates/rainbeam/src/routing/pages/circles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ struct ProfileTemplate {
notifs: usize,
circle: Circle,
responses: Vec<FullResponse>,
reactions: Vec<String>,
relationships: HashMap<String, RelationshipStatus>,
member_count: usize,
metadata: String,
Expand Down Expand Up @@ -335,20 +334,6 @@ pub async fn profile_request(
}
}

// collect all responses we've reacted to
let mut reactions: Vec<String> = Vec::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if let Ok(_) = database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
{
reactions.push(response.1.id.clone())
}
}
}

// ...
Html(
ProfileTemplate {
Expand All @@ -358,7 +343,6 @@ pub async fn profile_request(
notifs,
circle: circle.clone(),
responses,
reactions,
relationships,
member_count: database
.get_circle_memberships_count(circle.id.clone())
Expand All @@ -384,7 +368,6 @@ struct PartialProfileTemplate {
profile: Option<Profile>,
other: Circle,
responses: Vec<FullResponse>,
reactions: Vec<String>,
relationships: HashMap<String, RelationshipStatus>,
// ...
is_powerful: bool, // at least "manager"
Expand Down Expand Up @@ -477,28 +460,13 @@ pub async fn partial_profile_request(
}
}

// collect all responses we've reacted to
let mut reactions: Vec<String> = Vec::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if let Ok(_) = database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
{
reactions.push(response.1.id.clone())
}
}
}

// ...
Html(
PartialProfileTemplate {
config: database.server_options.clone(),
profile: auth_user.clone(),
other: circle.clone(),
responses,
reactions,
relationships,
// ...
is_powerful,
Expand Down
119 changes: 0 additions & 119 deletions crates/rainbeam/src/routing/pages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ struct TimelineTemplate {
notifs: usize,
responses: Vec<FullResponse>,
relationships: HashMap<String, RelationshipStatus>,
reactions: Vec<String>,
friends: Vec<(Profile, Profile)>,
is_powerful: bool,
is_helper: bool,
Expand Down Expand Up @@ -197,20 +196,6 @@ pub async fn homepage_request(
}
}

// collect all responses we've reacted to
let mut reactions: Vec<String> = Vec::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if let Ok(_) = database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
{
reactions.push(response.1.id.clone())
}
}
}

// ...
return Html(
TimelineTemplate {
Expand All @@ -220,7 +205,6 @@ pub async fn homepage_request(
notifs,
responses,
relationships,
reactions,
friends: database
.auth
.get_user_participating_relationships_of_status(
Expand Down Expand Up @@ -255,7 +239,6 @@ struct PartialTimelineTemplate {
profile: Option<Profile>,
responses: Vec<FullResponse>,
relationships: HashMap<String, RelationshipStatus>,
reactions: Vec<String>,
is_powerful: bool,
is_helper: bool,
}
Expand Down Expand Up @@ -329,26 +312,13 @@ pub async fn partial_timeline_request(
);
}

// collect all responses we've reacted to
let mut reactions: Vec<String> = Vec::new();

for response in &responses {
if let Ok(_) = database
.get_reaction(auth_user.id.clone(), response.1.id.clone())
.await
{
reactions.push(response.1.id.clone())
}
}

// ...
return Html(
PartialTimelineTemplate {
config: database.server_options,
profile: Some(auth_user.clone()),
responses,
relationships,
reactions,
is_powerful,
is_helper,
}
Expand Down Expand Up @@ -602,7 +572,6 @@ struct QuestionTemplate {
question: Question,
responses: Vec<FullResponse>,
reactions: Vec<Reaction>,
response_reactions: Vec<String>,
already_responded: bool,
is_powerful: bool,
is_helper: bool,
Expand Down Expand Up @@ -672,20 +641,6 @@ pub async fn question_request(
Err(e) => return Html(e.to_html(database)),
};

// collect all responses we've reacted to
let mut response_reactions: Vec<String> = Vec::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if let Ok(_) = database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
{
response_reactions.push(response.1.id.clone())
}
}
}

// ...
Html(
QuestionTemplate {
Expand All @@ -706,7 +661,6 @@ pub async fn question_request(
is_powerful,
is_helper,
reactions,
response_reactions,
}
.render()
.unwrap(),
Expand All @@ -722,7 +676,6 @@ struct PublicPostsTemplate {
notifs: usize,
page: i32,
responses: Vec<FullResponse>,
reactions: Vec<String>,
relationships: HashMap<String, RelationshipStatus>,
is_powerful: bool,
is_helper: bool,
Expand Down Expand Up @@ -848,20 +801,6 @@ pub async fn public_posts_timeline_request(
}
}

// collect all responses we've reacted to
let mut reactions: Vec<String> = Vec::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if let Ok(_) = database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
{
reactions.push(response.1.id.clone())
}
}
}

// ...
Html(
PublicPostsTemplate {
Expand All @@ -871,7 +810,6 @@ pub async fn public_posts_timeline_request(
notifs,
page: query.page,
responses,
reactions,
relationships,
is_powerful,
is_helper,
Expand All @@ -888,7 +826,6 @@ struct PartialPostsTemplate {
profile: Option<Profile>,
responses: Vec<FullResponse>,
relationships: HashMap<String, RelationshipStatus>,
reactions: Vec<String>,
is_powerful: bool,
is_helper: bool,
}
Expand Down Expand Up @@ -987,27 +924,12 @@ pub async fn partial_posts_request(
}
}

// collect all responses we've reacted to
let mut reactions: Vec<String> = Vec::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if let Ok(_) = database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
{
reactions.push(response.1.id.clone())
}
}
}

// ...
return Html(
PartialPostsTemplate {
config: database.server_options,
profile: auth_user,
responses,
reactions,
relationships,
is_powerful,
is_helper,
Expand All @@ -1027,7 +949,6 @@ struct FollowingPostsTemplate {
page: i32,
responses: Vec<FullResponse>,
relationships: HashMap<String, RelationshipStatus>,
reactions: Vec<String>,
is_powerful: bool,
is_helper: bool,
}
Expand Down Expand Up @@ -1110,18 +1031,6 @@ pub async fn following_posts_timeline_request(
group.permissions.contains(&Permission::Manager)
};

// collect all responses we've reacted to
let mut reactions: Vec<String> = Vec::new();

for response in &responses {
if let Ok(_) = database
.get_reaction(auth_user.id.clone(), response.1.id.clone())
.await
{
reactions.push(response.1.id.clone())
}
}

// ...
Html(
FollowingPostsTemplate {
Expand All @@ -1131,7 +1040,6 @@ pub async fn following_posts_timeline_request(
notifs,
page: query.page,
responses,
reactions,
relationships,
is_powerful,
is_helper,
Expand Down Expand Up @@ -1159,7 +1067,6 @@ struct ResponseTemplate {
anonymous_avatar: Option<String>,
is_powerful: bool,
is_helper: bool,
is_liked: bool,
}

/// GET /response/:id
Expand Down Expand Up @@ -1259,14 +1166,6 @@ pub async fn response_request(
relationship,
comments,
reactions,
is_liked: if let Some(ref ua) = auth_user {
database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
.is_ok()
} else {
false
},
page: query.page,
anonymous_username: Some("anonymous".to_string()), // TODO: fetch recipient setting
anonymous_avatar: None,
Expand All @@ -1293,7 +1192,6 @@ struct PartialResponseTemplate {
show_comments: bool,
show_pin_button: bool,
do_render_nested: bool,
is_liked: bool,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -1342,14 +1240,6 @@ pub async fn partial_response_request(
Html(
PartialResponseTemplate {
config: database.server_options.clone(),
is_liked: if let Some(ref ua) = auth_user {
database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
.is_ok()
} else {
false
},
profile: auth_user,
do_not_render_question: response.1.context.is_post,
is_pinned: false,
Expand Down Expand Up @@ -1385,7 +1275,6 @@ struct CommentTemplate {
anonymous_avatar: Option<String>,
is_powerful: bool,
is_helper: bool,
is_liked: bool,
}

/// GET /comment/:id
Expand Down Expand Up @@ -1464,14 +1353,6 @@ pub async fn comment_request(
Html(
CommentTemplate {
config: database.server_options.clone(),
is_liked: if let Some(ref ua) = auth_user {
database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
.is_ok()
} else {
false
},
profile: auth_user,
unread,
notifs,
Expand Down
Loading

0 comments on commit b14532a

Please sign in to comment.