[backend/database] Fix slow AddUserLastNoteAdd migration

This change ensures that the migration doesn't have to read every note in the database, but only up to one per known user.
This commit is contained in:
Laura Hausmann 2025-03-09 02:55:38 +01:00
parent 4b5a9386c7
commit 65d6edf799
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -20,7 +20,7 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
type: "timestamp with time zone", type: "timestamp with time zone",
nullable: true); nullable: true);
migrationBuilder.Sql("""UPDATE "user" SET "lastNoteAt" = (SELECT note."createdAt" FROM "note" WHERE "note"."userId" = "user"."id" ORDER BY "note"."createdAt" DESC LIMIT 1);"""); migrationBuilder.Sql("""UPDATE "user" SET "lastNoteAt" = (SELECT note."createdAt" FROM "note" WHERE "note"."userId" = "user"."id" ORDER BY "note"."id" DESC LIMIT 1);""");
} }
/// <inheritdoc /> /// <inheritdoc />