Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
cb94bf70
Commit
cb94bf70
authored
1 year ago
by
Eva Bardou
Committed by
Yoann Schneider
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Cache entities in the worker when calling the `list_corpus_entities` helper
parent
19d84704
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!466
Cache entities in the worker when calling the `list_corpus_entities` helper
Pipeline
#146888
passed
1 year ago
Stage: release
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/worker/entity.py
+9
-4
9 additions, 4 deletions
arkindex_worker/worker/entity.py
tests/test_elements_worker/test_entities.py
+5
-4
5 additions, 4 deletions
tests/test_elements_worker/test_entities.py
with
14 additions
and
8 deletions
arkindex_worker/worker/entity.py
+
9
−
4
View file @
cb94bf70
...
...
@@ -331,8 +331,7 @@ class EntityMixin:
parent
:
Element
|
None
=
None
,
):
"""
List all entities in the worker
'
s corpus
This method does not support cache
List all entities in the worker
'
s corpus and store them in the ``self.entities`` cache.
:param name: Filter entities by part of their name (case-insensitive)
:param parent: Restrict entities to those linked to all transcriptions of an element and all its descendants. Note that links to metadata are ignored.
"""
...
...
@@ -346,8 +345,14 @@ class EntityMixin:
assert
isinstance
(
parent
,
Element
),
"
parent should be of type Element
"
query_params
[
"
parent
"
]
=
parent
.
id
return
self
.
api_client
.
paginate
(
"
ListCorpusEntities
"
,
id
=
self
.
corpus_id
,
**
query_params
self
.
entities
=
{
entity
[
"
id
"
]:
entity
for
entity
in
self
.
api_client
.
paginate
(
"
ListCorpusEntities
"
,
id
=
self
.
corpus_id
,
**
query_params
)
}
logger
.
info
(
f
"
Loaded
{
len
(
self
.
entities
)
}
entities in corpus (
{
self
.
corpus_id
}
)
"
)
def
list_corpus_entity_types
(
...
...
This diff is collapsed.
Click to expand it.
tests/test_elements_worker/test_entities.py
+
5
−
4
View file @
cb94bf70
...
...
@@ -741,12 +741,13 @@ def test_list_corpus_entities(responses, mock_elements_worker):
},
)
# list is required to actually do the request
assert
list
(
mock_elements_worker
.
list_corpus_entities
())
==
[
{
mock_elements_worker
.
list_corpus_entities
()
assert
mock_elements_worker
.
entities
==
{
"
fake_entity_id
"
:
{
"
id
"
:
"
fake_entity_id
"
,
}
]
}
assert
len
(
responses
.
calls
)
==
len
(
BASE_API_CALLS
)
+
1
assert
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment