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. (de372975c7)

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 <earl-warren@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-09-16 08:54:14 +02:00 committed by Earl Warren
commit 548cd0c059

View file

@ -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,