From 24908993fae677782860e9c46585d4cd5e2d2ef2 Mon Sep 17 00:00:00 2001 From: Christian Beutel <> Date: Sat, 13 Sep 2025 12:36:22 +0200 Subject: [PATCH] adds index to activity_actors table --- .../1757759342_updated_activitypub_actors.go | 46 +++++++++++++++++++ web/src/hooks.server.ts | 2 +- .../v1/activitypub/user/[handle]/+server.ts | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 db/migrations/1757759342_updated_activitypub_actors.go diff --git a/db/migrations/1757759342_updated_activitypub_actors.go b/db/migrations/1757759342_updated_activitypub_actors.go new file mode 100644 index 00000000..40fd046a --- /dev/null +++ b/db/migrations/1757759342_updated_activitypub_actors.go @@ -0,0 +1,46 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_1295301207") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "indexes": [ + "CREATE UNIQUE INDEX `+"`"+`idx_rpT7QJwWTm`+"`"+` ON `+"`"+`activitypub_actors`+"`"+` (`+"`"+`iri`+"`"+`)", + "CREATE INDEX idx_actors_username_domain\nON activitypub_actors(preferred_username, domain);", + "CREATE INDEX idx_activitypub_actors_user ON activitypub_actors(user);" + ] + }`), &collection); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_1295301207") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "indexes": [ + "CREATE UNIQUE INDEX `+"`"+`idx_rpT7QJwWTm`+"`"+` ON `+"`"+`activitypub_actors`+"`"+` (`+"`"+`iri`+"`"+`)" + ] + }`), &collection); err != nil { + return err + } + + return app.Save(collection) + }) +} diff --git a/web/src/hooks.server.ts b/web/src/hooks.server.ts index 32fdb41a..ddf3e400 100644 --- a/web/src/hooks.server.ts +++ b/web/src/hooks.server.ts @@ -83,7 +83,7 @@ const auth: Handle = async ({ event, resolve }) => { if (pb.authStore.record) { meiliApiKey = pb.authStore.record.token settings = await pb.collection('settings').getFirstListItem(`user="${pb.authStore.record.id}"`, { requestKey: null }) - actor = await pb.collection("activitypub_actors").getFirstListItem(`user='${pb.authStore.record.id}'`) + actor = await pb.collection("activitypub_actors").getFirstListItem(`isLocal=1&&user='${pb.authStore.record.id}'`) } else { if (!publicMeilisearchKey) { const response = await pb.send("/public/search/token", { method: "GET", fetch: event.fetch }); diff --git a/web/src/routes/api/v1/activitypub/user/[handle]/+server.ts b/web/src/routes/api/v1/activitypub/user/[handle]/+server.ts index bc8460b2..0d77cbfa 100644 --- a/web/src/routes/api/v1/activitypub/user/[handle]/+server.ts +++ b/web/src/routes/api/v1/activitypub/user/[handle]/+server.ts @@ -20,7 +20,7 @@ export async function GET(event: RequestEvent) { const [username, domain] = splitUsername(fullUsername, env.ORIGIN) - const actor: Actor = await event.locals.pb.collection("activitypub_actors").getFirstListItem(`preferred_username:lower='${username?.toLowerCase()}'&&isLocal=true`) + const actor: Actor = await event.locals.pb.collection("activitypub_actors").getFirstListItem(`preferred_username:lower='${username?.toLowerCase()}'&&isLocal=1`) const user: UserAnonymous = await event.locals.pb.collection("users_anonymous").getOne(actor.user!)