From 2c147015f429f886786b21fa2f5323cd606a54e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 23 Oct 2026 16:57:13 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20perf:=20sidebar=20shows=20your=205?= =?UTF-8?q?=20freshest=20repositories=20and=20links=20to=20the=20rest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-web/src/i18n/orgs.rs | 4 +++ crates/forge-web/src/views/mod.rs | 47 +++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/crates/forge-web/src/i18n/orgs.rs b/crates/forge-web/src/i18n/orgs.rs index 4e2a044..d684380 100644 --- a/crates/forge-web/src/i18n/orgs.rs +++ b/crates/forge-web/src/i18n/orgs.rs @@ -128,6 +128,7 @@ pub enum K { SetUpForge, YourRepositories, NoReposYet, + ViewAllRepositories, } pub fn t(lang: Lang, key: K) -> &'static str { @@ -382,6 +383,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { (YourRepositories, Tr) => "Depolarınız", (NoReposYet, En) => "You have no repositories yet.", (NoReposYet, Tr) => "Henüz deponuz yok.", + (ViewAllRepositories, En) => "View all repositories", + (ViewAllRepositories, Tr) => "Tüm depoları gör", } } @@ -611,6 +614,7 @@ mod tests { K::SetUpForge, K::YourRepositories, K::NoReposYet, + K::ViewAllRepositories, ]; #[test] diff --git a/crates/forge-web/src/views/mod.rs b/crates/forge-web/src/views/mod.rs index cdee35e..5d3907c 100644 --- a/crates/forge-web/src/views/mod.rs +++ b/crates/forge-web/src/views/mod.rs @@ -9,6 +9,8 @@ pub mod review_thread; use std::sync::OnceLock; +use forge_core::store::RepoSort; +use forge_core::store::repo_listing::RepoScope; use forge_core::{Error as CoreError, Session, User}; use hex::encode; use http::header::{ @@ -90,6 +92,9 @@ fn csp_header(base_url: &str) -> HeaderValue { HeaderValue::from_str(&policy).unwrap_or_else(|_| HeaderValue::from_static(CSP)) } +/// How many repos the signed-in sidebar lists, freshest first. +const SIDE_REPOS: u64 = 5; + /// A repo link in the signed-in sidebar. #[derive(Clone)] struct SideRepo { @@ -128,22 +133,32 @@ pub async fn shell( #[default] child: Child<'_>, ) -> Result { let full_title = format!("{title} \u{b7} forge"); - // The bell count and the viewer's repos for the sidebar: two queries, signed-in only. - let (unread, repos) = match viewer { + // The bell count and the viewer's freshest repos for the sidebar, with the total: two queries, + // signed-in only. + let (unread, (listed, repo_total)) = match viewer { Some((user, _)) => match try_app_context::(__cx) { Some(state) => ( state.store.unread_count(&user.id).await?, - state.store.list_repos_by_owner(&user.id).await?, + state + .store + .list_visible_repos( + RepoScope::OwnedBy(&user.id), + Some(user), + None, + RepoSort::RecentlyUpdated, + 1, + SIDE_REPOS, + ) + .await?, ), - None => (0, Vec::new()), + None => (0, (Vec::new(), 0)), }, - None => (0, Vec::new()), + None => (0, (Vec::new(), 0)), }; let unread_badge = (unread > 0).then(|| unread.to_string()); - let side_repos: Vec = repos + let side_repos: Vec = listed .iter() - .take(8) - .map(|repo| SideRepo { + .map(|(repo, _, _)| SideRepo { name: repo.name.clone(), href: repo_href(&repo.owner_name, &repo.name, "", ""), }) @@ -151,7 +166,9 @@ pub async fn shell( // The viewer's own profile Repositories tab has its own sidebar key, so the pinned link lights up there. let own_repos_tab = viewer.is_some_and(|(user, _)| { uri(__cx).path().trim_matches('/') == user.username - && uri(__cx).query().is_some_and(|q| q.split('&').any(|p| p == "tab=repositories")) + && uri(__cx) + .query() + .is_some_and(|q| q.split('&').any(|p| p == "tab=repositories")) }); let current = if own_repos_tab { "repositories" @@ -176,6 +193,8 @@ pub async fn shell( let theme_csrf = viewer.map(|(_, session)| session.csrf_token.clone()); let back = uri(__cx).path_and_query().map(|p| p.as_str().to_owned()); let lang = i18n::lang(__cx, viewer.map(|(user, _)| user)); + let side_more = (repo_total > SIDE_REPOS) + .then(|| format!("{} ({repo_total})", o::t(lang, OK::ViewAllRepositories))); let banner = crate::pages::banner::current(__cx); let banner_back = back.clone().unwrap_or_else(|| "/".to_owned()); let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss); @@ -268,6 +287,8 @@ pub async fn shell( let notif_label = t(lang, Key::Notifications); let menu_label = t(lang, Key::SiteMenu); let side_repos_menu = side_repos.clone(); + let side_more_menu = side_more.clone(); + let side_more_aside = side_more; let unread_menu = unread_badge.clone(); let unread_aside = unread_badge.clone(); Ok(view! { @@ -304,7 +325,7 @@ pub async fn shell( if let Some(section) = section_menu { section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) } else { - side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_menu, repos: side_repos_menu) + side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_menu, more: side_more_menu, repos: side_repos_menu) } @@ -391,7 +412,7 @@ pub async fn shell( if let Some(section) = section { section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) } else { - side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_aside, repos: side_repos) + side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_aside, more: side_more_aside, repos: side_repos) } } @@ -429,6 +450,7 @@ async fn side_nav( current: &str, profile_repos_href: &str, unread: Option, + more: Option, repos: Vec, ) -> Result { let dashboard = current == "dashboard"; @@ -482,6 +504,9 @@ async fn side_nav( for repo in repos.into_iter() { (repo.name.as_str()) } + if let Some(label) = more { + (label.as_str()) + } }