From 548cd0c05950c865aa963a1e65fa9d3532d5add5 Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 16 Sep 2025 08:54:14 +0200 Subject: [PATCH] feat: avoid expensive SQL for org home (#9309) This change comes from Codeberg's Forgejo fork and has been in deployed in production for a month now. (https://codeberg.org/Codeberg-Infrastructure/forgejo/commit/de372975c703b1368ce6d538de1b21f20c6f3a84) What we noticed on Codeberg is that navigating to the organisation's home was quite slow, for example https://codeberg.org/forgejo, this was caused by searching for the repositories that is owned by the organisation. The expensive part of this SQL was that it tried to show repositories where the organisation is a collaborator of... which is none as you cannot add organisations as a collaborator. Not doing this made the SQL query very fast again. There's no test associated with this, as it's essentially a no-op before and after. So no testing would fail without this change. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9309 Reviewed-by: Earl Warren Co-authored-by: Gusted Co-committed-by: Gusted --- routers/web/org/home.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 87e69e7a6b..5ca268197d 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -19,6 +19,7 @@ import ( "forgejo.org/modules/log" "forgejo.org/modules/markup" "forgejo.org/modules/markup/markdown" + "forgejo.org/modules/optional" "forgejo.org/modules/setting" "forgejo.org/modules/util" shared_user "forgejo.org/routers/web/shared/user" @@ -101,6 +102,7 @@ func Home(ctx *context.Context) { }, Keyword: keyword, OwnerID: org.ID, + Collaborate: optional.Some(false), // A organisation doesn't collaborate to any repository, avoid doing expensive SQL query. OrderBy: orderBy, Private: ctx.IsSigned, Actor: ctx.Doer,