mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 18:46:19 +08:00
feat(server): get recently updated docs (#12861)
close AI-218 #### PR Dependency Tree * **PR #12861** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a "Recently Updated Documents" feature, allowing users to view a paginated list of the most recently updated documents within a workspace. - Document metadata now includes a "title" field for easier identification. - **Tests** - Introduced new end-to-end tests to verify the recently updated documents query and its pagination behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -636,5 +636,61 @@ export class DocModel extends BaseModel {
|
||||
|
||||
return [count, rows] as const;
|
||||
}
|
||||
|
||||
async paginateDocInfoByUpdatedAt(
|
||||
workspaceId: string,
|
||||
pagination: PaginationInput
|
||||
) {
|
||||
const count = await this.db.workspaceDoc.count({
|
||||
where: {
|
||||
workspaceId,
|
||||
},
|
||||
});
|
||||
|
||||
const after = pagination.after
|
||||
? Prisma.sql`AND "snapshots"."updated_at" < ${new Date(pagination.after)}`
|
||||
: Prisma.sql``;
|
||||
|
||||
const rows = await this.db.$queryRaw<
|
||||
{
|
||||
workspaceId: string;
|
||||
docId: string;
|
||||
mode: PublicDocMode;
|
||||
public: boolean;
|
||||
defaultRole: DocRole;
|
||||
title: string | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
creatorId?: string;
|
||||
lastUpdaterId?: string;
|
||||
}[]
|
||||
>`
|
||||
SELECT
|
||||
"workspace_pages"."workspace_id" as "workspaceId",
|
||||
"workspace_pages"."page_id" as "docId",
|
||||
"workspace_pages"."mode" as "mode",
|
||||
"workspace_pages"."public" as "public",
|
||||
"workspace_pages"."defaultRole" as "defaultRole",
|
||||
"workspace_pages"."title" as "title",
|
||||
"snapshots"."created_at" as "createdAt",
|
||||
"snapshots"."updated_at" as "updatedAt",
|
||||
"snapshots"."created_by" as "creatorId",
|
||||
"snapshots"."updated_by" as "lastUpdaterId"
|
||||
FROM "workspace_pages"
|
||||
INNER JOIN "snapshots"
|
||||
ON "workspace_pages"."workspace_id" = "snapshots"."workspace_id"
|
||||
AND "workspace_pages"."page_id" = "snapshots"."guid"
|
||||
WHERE
|
||||
"workspace_pages"."workspace_id" = ${workspaceId}
|
||||
${after}
|
||||
ORDER BY
|
||||
"snapshots"."updated_at" DESC
|
||||
LIMIT ${pagination.first}
|
||||
OFFSET ${pagination.offset}
|
||||
`;
|
||||
|
||||
return [count, rows] as const;
|
||||
}
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user