Skip to content

Commit 0e85881

Browse files
committed
Only request full resource coverage data when needed
Closes #1083
1 parent 923cb50 commit 0e85881

File tree

4 files changed

+268
-58
lines changed

4 files changed

+268
-58
lines changed

Tekst-API/openapi.json

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8361,6 +8361,23 @@
83618361
}
83628362
}
83638363
},
8364+
"coverage": {
8365+
"anyOf": [
8366+
{
8367+
"items": {
8368+
"type": "integer"
8369+
},
8370+
"type": "array",
8371+
"maxItems": 2,
8372+
"minItems": 2
8373+
},
8374+
{
8375+
"type": "null"
8376+
}
8377+
],
8378+
"title": "Coverage",
8379+
"description": "Location coverage of this resource by contents, locations"
8380+
},
83648381
"contentsChangedAt": {
83658382
"type": "string",
83668383
"format": "date-time",
@@ -9192,6 +9209,23 @@
91929209
}
91939210
}
91949211
},
9212+
"coverage": {
9213+
"anyOf": [
9214+
{
9215+
"items": {
9216+
"type": "integer"
9217+
},
9218+
"type": "array",
9219+
"maxItems": 2,
9220+
"minItems": 2
9221+
},
9222+
{
9223+
"type": "null"
9224+
}
9225+
],
9226+
"title": "Coverage",
9227+
"description": "Location coverage of this resource by contents, locations"
9228+
},
91959229
"contentsChangedAt": {
91969230
"type": "string",
91979231
"format": "date-time",
@@ -10937,6 +10971,23 @@
1093710971
}
1093810972
}
1093910973
},
10974+
"coverage": {
10975+
"anyOf": [
10976+
{
10977+
"items": {
10978+
"type": "integer"
10979+
},
10980+
"type": "array",
10981+
"maxItems": 2,
10982+
"minItems": 2
10983+
},
10984+
{
10985+
"type": "null"
10986+
}
10987+
],
10988+
"title": "Coverage",
10989+
"description": "Location coverage of this resource by contents, locations"
10990+
},
1094010991
"contentsChangedAt": {
1094110992
"type": "string",
1094210993
"format": "date-time",
@@ -11972,6 +12023,23 @@
1197212023
}
1197312024
}
1197412025
},
12026+
"coverage": {
12027+
"anyOf": [
12028+
{
12029+
"items": {
12030+
"type": "integer"
12031+
},
12032+
"type": "array",
12033+
"maxItems": 2,
12034+
"minItems": 2
12035+
},
12036+
{
12037+
"type": "null"
12038+
}
12039+
],
12040+
"title": "Coverage",
12041+
"description": "Location coverage of this resource by contents, locations"
12042+
},
1197512043
"contentsChangedAt": {
1197612044
"type": "string",
1197712045
"format": "date-time",
@@ -13350,6 +13418,23 @@
1335013418
}
1335113419
}
1335213420
},
13421+
"coverage": {
13422+
"anyOf": [
13423+
{
13424+
"items": {
13425+
"type": "integer"
13426+
},
13427+
"type": "array",
13428+
"maxItems": 2,
13429+
"minItems": 2
13430+
},
13431+
{
13432+
"type": "null"
13433+
}
13434+
],
13435+
"title": "Coverage",
13436+
"description": "Location coverage of this resource by contents, locations"
13437+
},
1335313438
"contentsChangedAt": {
1335413439
"type": "string",
1335513440
"format": "date-time",
@@ -14566,6 +14651,23 @@
1456614651
}
1456714652
}
1456814653
},
14654+
"coverage": {
14655+
"anyOf": [
14656+
{
14657+
"items": {
14658+
"type": "integer"
14659+
},
14660+
"type": "array",
14661+
"maxItems": 2,
14662+
"minItems": 2
14663+
},
14664+
{
14665+
"type": "null"
14666+
}
14667+
],
14668+
"title": "Coverage",
14669+
"description": "Location coverage of this resource by contents, locations"
14670+
},
1456914671
"contentsChangedAt": {
1457014672
"type": "string",
1457114673
"format": "date-time",
@@ -16566,6 +16668,23 @@
1656616668
}
1656716669
}
1656816670
},
16671+
"coverage": {
16672+
"anyOf": [
16673+
{
16674+
"items": {
16675+
"type": "integer"
16676+
},
16677+
"type": "array",
16678+
"maxItems": 2,
16679+
"minItems": 2
16680+
},
16681+
{
16682+
"type": "null"
16683+
}
16684+
],
16685+
"title": "Coverage",
16686+
"description": "Location coverage of this resource by contents, locations"
16687+
},
1656916688
"contentsChangedAt": {
1657016689
"type": "string",
1657116690
"format": "date-time",
@@ -17793,6 +17912,23 @@
1779317912
}
1779417913
}
1779517914
},
17915+
"coverage": {
17916+
"anyOf": [
17917+
{
17918+
"items": {
17919+
"type": "integer"
17920+
},
17921+
"type": "array",
17922+
"maxItems": 2,
17923+
"minItems": 2
17924+
},
17925+
{
17926+
"type": "null"
17927+
}
17928+
],
17929+
"title": "Coverage",
17930+
"description": "Location coverage of this resource by contents, locations"
17931+
},
1779617932
"contentsChangedAt": {
1779717933
"type": "string",
1779817934
"format": "date-time",

Tekst-API/tekst/models/resource.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ class ResourceBase(ModelBase, ModelFactoryMixin):
228228

229229
config: ResourceConfigBase = ResourceConfigBase()
230230

231+
coverage: Annotated[
232+
list[int] | None,
233+
Field(
234+
min_length=2,
235+
max_length=2,
236+
description="Location coverage of this resource by contents, locations",
237+
),
238+
ExcludeFromModelVariants(
239+
update=True,
240+
create=True,
241+
),
242+
] = None
243+
231244
contents_changed_at: Annotated[
232245
AwareDatetime,
233246
Field(
@@ -447,7 +460,7 @@ async def __precompute_coverage_data(
447460
for p_id, loc_cov in coverage_per_parent.items()
448461
]
449462

450-
# generate coverage ranges data
463+
# collect coverage ranges data
451464
ranges = []
452465
curr_range: dict[str, str | bool] | None = None
453466
for location in data:
@@ -468,6 +481,10 @@ async def __precompute_coverage_data(
468481
if curr_range:
469482
# append the last remaining coverage range
470483
ranges.append(curr_range)
484+
# save locations count, deref data
485+
loc_count = len(data)
486+
data = None
487+
# evaluate ranges data
471488
covered_count = len([r for r in ranges if r.get("covered")])
472489
missing_count = len(ranges) - covered_count
473490
use_covered_ranges = (
@@ -479,17 +496,22 @@ async def __precompute_coverage_data(
479496
if r.get("covered") == use_covered_ranges
480497
]
481498

499+
# compose and save precomputed coverage data
482500
precomp_doc.data = ResourceCoverage(
483501
covered=covered_locations_count,
484-
total=len(data),
502+
total=loc_count,
485503
ranges=ranges,
486504
ranges_covered=use_covered_ranges,
487505
details=details,
488506
).model_dump()
489-
490507
precomp_doc.created_at = datetime.now(UTC)
491508
await precomp_doc.save()
492509

510+
# save basic coverage data to resource document directly
511+
await ResourceBaseDocument.find_one(
512+
ResourceBaseDocument.id == self.id, with_children=True
513+
).set({ResourceBaseDocument.coverage: [covered_locations_count, loc_count]})
514+
493515

494516
# generate document and update models for this base model,
495517
# as those have to be used as bases for inheriting model's document/update models

Tekst-Web/src/api/schema.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,11 @@ export interface components {
17261726
* }
17271727
* } */
17281728
config: components['schemas']['ApiCallResourceConfig'];
1729+
/**
1730+
* Coverage
1731+
* @description Location coverage of this resource by contents, locations
1732+
*/
1733+
coverage?: number[] | null;
17291734
/**
17301735
* Contentschangedat
17311736
* Format: date-time
@@ -2102,6 +2107,11 @@ export interface components {
21022107
* }
21032108
* } */
21042109
config: components['schemas']['AudioResourceConfig'];
2110+
/**
2111+
* Coverage
2112+
* @description Location coverage of this resource by contents, locations
2113+
*/
2114+
coverage?: number[] | null;
21052115
/**
21062116
* Contentschangedat
21072117
* Format: date-time
@@ -2919,6 +2929,11 @@ export interface components {
29192929
* }
29202930
* } */
29212931
config: components['schemas']['ExternalReferencesResourceConfig'];
2932+
/**
2933+
* Coverage
2934+
* @description Location coverage of this resource by contents, locations
2935+
*/
2936+
coverage?: number[] | null;
29222937
/**
29232938
* Contentschangedat
29242939
* Format: date-time
@@ -3407,6 +3422,11 @@ export interface components {
34073422
* }
34083423
* } */
34093424
config: components['schemas']['ImagesResourceConfig'];
3425+
/**
3426+
* Coverage
3427+
* @description Location coverage of this resource by contents, locations
3428+
*/
3429+
coverage?: number[] | null;
34103430
/**
34113431
* Contentschangedat
34123432
* Format: date-time
@@ -4048,6 +4068,11 @@ export interface components {
40484068
* }
40494069
* } */
40504070
config: components['schemas']['LocationMetadataResourceConfig'];
4071+
/**
4072+
* Coverage
4073+
* @description Location coverage of this resource by contents, locations
4074+
*/
4075+
coverage?: number[] | null;
40514076
/**
40524077
* Contentschangedat
40534078
* Format: date-time
@@ -4626,6 +4651,11 @@ export interface components {
46264651
* }
46274652
* } */
46284653
config: components['schemas']['PlainTextResourceConfig'];
4654+
/**
4655+
* Coverage
4656+
* @description Location coverage of this resource by contents, locations
4657+
*/
4658+
coverage?: number[] | null;
46294659
/**
46304660
* Contentschangedat
46314661
* Format: date-time
@@ -5591,6 +5621,11 @@ export interface components {
55915621
* }
55925622
* } */
55935623
config: components['schemas']['RichTextResourceConfig'];
5624+
/**
5625+
* Coverage
5626+
* @description Location coverage of this resource by contents, locations
5627+
*/
5628+
coverage?: number[] | null;
55945629
/**
55955630
* Contentschangedat
55965631
* Format: date-time
@@ -6167,6 +6202,11 @@ export interface components {
61676202
* }
61686203
* } */
61696204
config: components['schemas']['TextAnnotationResourceConfig'];
6205+
/**
6206+
* Coverage
6207+
* @description Location coverage of this resource by contents, locations
6208+
*/
6209+
coverage?: number[] | null;
61706210
/**
61716211
* Contentschangedat
61726212
* Format: date-time

0 commit comments

Comments
 (0)