Skip to content

Commit f305bed

Browse files
committed
smoother operatoin with CDN
1 parent 48615d4 commit f305bed

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

papermerge/core/features/document/schema.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,15 @@ def thumbnail_url(value, info):
189189
ThumbnailUrl = Annotated[str | None, Field(validate_default=True)]
190190

191191

192-
class Document(BaseModel):
192+
class DocumentNode(BaseModel):
193+
"""Document without versions
194+
195+
The point of this class is to be used when listing folders/documents in
196+
which case info about document versions (and their pages etc) is not
197+
required (generating document version info in context of CDN is very
198+
slow as for each page of each doc ver signed URL must be computed)
199+
"""
200+
193201
id: UUID
194202
title: str
195203
ctype: Literal["document"]
@@ -199,7 +207,6 @@ class Document(BaseModel):
199207
parent_id: UUID | None
200208
document_type_id: UUID | None = None
201209
breadcrumb: list[tuple[UUID, str]] = []
202-
versions: list[DocumentVersion] | None = []
203210
ocr: bool = True # will this document be OCRed?
204211
ocr_status: OCRStatusEnum = OCRStatusEnum.unknown
205212
thumbnail_url: ThumbnailUrl = None
@@ -221,6 +228,10 @@ def thumbnail_url_validator(cls, value, info):
221228
model_config = ConfigDict(from_attributes=True)
222229

223230

231+
class Document(DocumentNode):
232+
versions: list[DocumentVersion] | None = []
233+
234+
224235
class NewDocument(BaseModel):
225236
# UUID may be present to allow custom IDs
226237
# See https://github.com/papermerge/papermerge-core/issues/325

papermerge/core/features/nodes/db/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ def get_paginated_nodes(
137137
if node.ctype == "folder":
138138
items.append(schema.Folder.model_validate(node))
139139
else:
140-
items.append(schema.Document.model_validate(node))
140+
items.append(schema.DocumentNode.model_validate(node))
141141

142-
return PaginatedResponse[Union[schema.Document, schema.Folder]](
142+
return PaginatedResponse[Union[schema.DocumentNode, schema.Folder]](
143143
page_size=page_size,
144144
page_number=page_number,
145145
num_pages=num_pages,

papermerge/core/features/nodes/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_node(
4242
parent_id: UUID,
4343
user: Annotated[schema.User, Security(get_current_user, scopes=[scopes.NODE_VIEW])],
4444
params: CommonQueryParams = Depends(),
45-
) -> PaginatedResponse[Union[schema.Document, schema.Folder]]:
45+
) -> PaginatedResponse[Union[schema.DocumentNode, schema.Folder]]:
4646
"""Returns list of *paginated* direct descendants of `parent_id` node
4747
4848
Required scope: `{scope}`

papermerge/core/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
)
1111
from .features.document.schema import (
1212
Document,
13+
DocumentNode,
1314
NewDocument,
1415
DocumentVersion,
1516
Page,
@@ -43,6 +44,7 @@
4344
'UpdateNode',
4445
'MoveNode',
4546
'Document',
47+
'DocumentNode',
4648
'NewDocument',
4749
'DocumentVersion',
4850
'Page',

0 commit comments

Comments
 (0)