mirror of
https://github.com/outline/outline.git
synced 2026-11-21 13:34:02 +03:00
* perf: Add team-scoped composite index for document search The global tsvector GIN index scanned matches across all teams before filtering by teamId. A composite (teamId, searchVector) index via btree_gin confines the scan to a single team's documents. * fix: Bound search queries with the request statement timeout Search queries ran outside a transaction and so never received the SET LOCAL statement_timeout applied to request-handling processes, leaving cancelled requests running unbounded on the database. * Bind queries to read-only replica where available * Remove readOnly option for now --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import type { Sequelize } from "sequelize-typescript";
|
|
import Document from "@server/models/Document";
|
|
import { buildDocument, buildTeam } from "@server/test/factories";
|
|
import env from "@server/env";
|
|
import { createDatabaseInstance } from "./database";
|
|
|
|
describe("read replica transactions", () => {
|
|
let replica: Sequelize;
|
|
|
|
beforeAll(() => {
|
|
// A second connection to the same test database stands in for a replica.
|
|
replica = createDatabaseInstance(
|
|
env.DATABASE_URL ?? "",
|
|
{},
|
|
{ readOnly: true }
|
|
);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await replica.close();
|
|
});
|
|
|
|
it("should execute a findAll on the transaction's connection when the transaction is opened on another instance", async () => {
|
|
const team = await buildTeam();
|
|
const document = await buildDocument({ teamId: team.id });
|
|
|
|
const documents = await replica.transaction(async (transaction) => {
|
|
const connection = (
|
|
transaction as unknown as {
|
|
connection: { query: (...args: unknown[]) => unknown };
|
|
}
|
|
).connection;
|
|
const spy = vi.spyOn(connection, "query");
|
|
|
|
const results = await Document.unscoped().findAll({
|
|
attributes: ["id"],
|
|
where: { teamId: team.id },
|
|
transaction,
|
|
});
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
return results;
|
|
});
|
|
|
|
expect(documents.map((d) => d.id)).toEqual([document.id]);
|
|
});
|
|
});
|