fix: improved performance by truncating not displayed text

This commit is contained in:
Per Stark
2025-09-22 15:37:55 +02:00
parent f592eb7200
commit 903585bfef
5 changed files with 52 additions and 7 deletions
+9 -4
View File
@@ -17,6 +17,7 @@ use crate::{
auth_middleware::RequireUser,
response_middleware::{HtmlError, TemplateResponse},
},
utils::text_content_preview::truncate_text_contents,
};
#[derive(Serialize)]
@@ -58,6 +59,8 @@ pub async fn show_content_page(
User::get_text_contents(&user.id, &state.db).await?
};
let text_contents = truncate_text_contents(text_contents);
let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?;
let data = ContentPageData {
user,
@@ -117,7 +120,8 @@ pub async fn patch_text_content(
TextContent::patch(&id, &form.context, &form.category, &form.text, &state.db).await?;
if target.as_deref() == Some("latest_content_section") {
let text_contents = User::get_latest_text_contents(&user.id, &state.db).await?;
let text_contents =
truncate_text_contents(User::get_latest_text_contents(&user.id, &state.db).await?);
return Ok(TemplateResponse::new_template(
"dashboard/recent_content.html",
@@ -128,7 +132,7 @@ pub async fn patch_text_content(
));
}
let text_contents = User::get_text_contents(&user.id, &state.db).await?;
let text_contents = truncate_text_contents(User::get_text_contents(&user.id, &state.db).await?);
let categories = User::get_user_categories(&user.id, &state.db).await?;
let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?;
@@ -166,7 +170,7 @@ pub async fn delete_text_content(
state.db.delete_item::<TextContent>(&id).await?;
// Get updated content, categories and return the refreshed list
let text_contents = User::get_text_contents(&user.id, &state.db).await?;
let text_contents = truncate_text_contents(User::get_text_contents(&user.id, &state.db).await?);
let categories = User::get_user_categories(&user.id, &state.db).await?;
let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?;
@@ -205,7 +209,8 @@ pub async fn show_recent_content(
State(state): State<HtmlState>,
RequireUser(user): RequireUser,
) -> Result<impl IntoResponse, HtmlError> {
let text_contents = User::get_latest_text_contents(&user.id, &state.db).await?;
let text_contents =
truncate_text_contents(User::get_latest_text_contents(&user.id, &state.db).await?);
Ok(TemplateResponse::new_template(
"dashboard/recent_content.html",
+6 -3
View File
@@ -9,10 +9,12 @@ use serde::Serialize;
use tokio::join;
use crate::{
html_state::HtmlState,
middlewares::{
auth_middleware::RequireUser,
response_middleware::{HtmlError, TemplateResponse},
},
utils::text_content_preview::truncate_text_contents,
AuthSessionType,
};
use common::storage::store;
@@ -26,8 +28,6 @@ use common::{
},
};
use crate::html_state::HtmlState;
#[derive(Serialize)]
pub struct IndexPageData {
user: Option<User>,
@@ -52,6 +52,8 @@ pub async fn index_handler(
User::get_unfinished_ingestion_tasks(&user.id, &state.db)
)?;
let text_contents = truncate_text_contents(text_contents);
Ok(TemplateResponse::new_template(
"dashboard/base.html",
IndexPageData {
@@ -94,7 +96,8 @@ pub async fn delete_text_content(
);
// Render updated content
let latest_text_contents = User::get_latest_text_contents(&user.id, &state.db).await?;
let latest_text_contents =
truncate_text_contents(User::get_latest_text_contents(&user.id, &state.db).await?);
Ok(TemplateResponse::new_partial(
"index/signed_in/recent_content.html",