mirror of
https://github.com/outline/outline.git
synced 2026-11-28 08:14:58 +03:00
perf: Skip the text column when loading document lists (#14138)
This commit is contained in:
1 parent
978c05bb17
commit
4bd64340a4
4 files changed
+56
-3
No files matched your search
@@ -793,6 +793,43 @@ describe("#findByPk", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#withMembershipScope", () => {
|
||||
it("should not load text for documents with content", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
text: "Hello world",
|
||||
});
|
||||
|
||||
const [loaded] = await Document.withMembershipScope(user.id).findAll({
|
||||
where: { id: document.id },
|
||||
});
|
||||
|
||||
expect(loaded.content).toBeTruthy();
|
||||
expect(loaded.text).toBeNull();
|
||||
});
|
||||
|
||||
it("should load text for documents without content or state", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
text: "Hello world",
|
||||
});
|
||||
await sequelize.query(
|
||||
`UPDATE documents SET content = NULL, state = NULL WHERE id = :id`,
|
||||
{ replacements: { id: document.id } }
|
||||
);
|
||||
|
||||
const [loaded] = await Document.withMembershipScope(user.id).findAll({
|
||||
where: { id: document.id },
|
||||
});
|
||||
|
||||
expect(loaded.text).toEqual("Hello world");
|
||||
});
|
||||
});
|
||||
|
||||
describe("findByIds", () => {
|
||||
test("should return documents by ids", async () => {
|
||||
const document1 = await buildDocument();
|
||||
|
||||
@@ -97,6 +97,15 @@ const stateIfContentEmpty: ProjectionAlias = [
|
||||
"state",
|
||||
];
|
||||
|
||||
// The markdown text column is only needed to deserialize documents that have
|
||||
// neither content nor state.
|
||||
const textIfContentAndStateEmpty: ProjectionAlias = [
|
||||
Sequelize.literal(
|
||||
`CASE WHEN document.content IS NULL AND document.state IS NULL THEN document.text ELSE NULL END`
|
||||
),
|
||||
"text",
|
||||
];
|
||||
|
||||
type AdditionalFindOptions = {
|
||||
/** The user ID to load associated permissions for. */
|
||||
userId?: string;
|
||||
@@ -166,6 +175,12 @@ const publishedWhere: WhereOptions<Document> = {
|
||||
include: [stateIfContentEmpty],
|
||||
},
|
||||
},
|
||||
withoutStateOrText: {
|
||||
attributes: {
|
||||
exclude: ["state", "text"],
|
||||
include: [stateIfContentEmpty, textIfContentAndStateEmpty],
|
||||
},
|
||||
},
|
||||
withoutContent: {
|
||||
attributes: {
|
||||
exclude: ["state", "content", "text"],
|
||||
@@ -890,7 +905,7 @@ class Document extends ArchivableModel<
|
||||
) {
|
||||
return this.scope([
|
||||
options?.includeDrafts ? "withDrafts" : "defaultScope",
|
||||
"withoutState",
|
||||
"withoutStateOrText",
|
||||
{
|
||||
method: ["withViews", userId],
|
||||
},
|
||||
|
||||
@@ -79,7 +79,8 @@ let baseDomain;
|
||||
@DefaultScope(() => ({
|
||||
include: [
|
||||
{
|
||||
association: "document",
|
||||
model: Document.scope(["defaultScope", "withoutStateOrText"]),
|
||||
as: "document",
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -624,7 +624,7 @@ router.post(
|
||||
{
|
||||
model: Document.scope([
|
||||
"withDrafts",
|
||||
"withoutState",
|
||||
"withoutStateOrText",
|
||||
{ method: ["withMembership", userId] },
|
||||
]),
|
||||
required: true,
|
||||
|
||||
Reference in new issue
Block a user