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
3e610b20
Commit
3e610b20
authored
3 years ago
by
Eva Bardou
Browse files
Options
Downloads
Patches
Plain Diff
Create missing tables in parents caches before merge
parent
8641248c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!91
Create missing tables in parents caches before merge
Pipeline
#78460
passed
3 years ago
Stage: test
Stage: build
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/cache.py
+6
-0
6 additions, 0 deletions
arkindex_worker/cache.py
tests/test_merge.py
+12
-0
12 additions, 0 deletions
tests/test_merge.py
with
18 additions
and
0 deletions
arkindex_worker/cache.py
+
6
−
0
View file @
3e610b20
...
...
@@ -188,13 +188,19 @@ def merge_parents_cache(parent_ids, current_database, data_dir="/data", chunk=No
# Merge each table into the local database
for
idx
,
path
in
enumerate
(
paths
):
with
SqliteDatabase
(
path
)
as
source
:
with
source
.
bind_ctx
(
MODELS
):
source
.
create_tables
(
MODELS
)
logger
.
info
(
f
"
Merging parent db
{
path
}
into
{
current_database
}
"
)
statements
=
[
"
PRAGMA page_size=80000;
"
,
"
PRAGMA synchronous=OFF;
"
,
f
"
ATTACH DATABASE
'
{
path
}
'
AS source_
{
idx
}
;
"
,
f
"
REPLACE INTO images SELECT * FROM source_
{
idx
}
.images;
"
,
f
"
REPLACE INTO elements SELECT * FROM source_
{
idx
}
.elements;
"
,
f
"
REPLACE INTO transcriptions SELECT * FROM source_
{
idx
}
.transcriptions;
"
,
f
"
REPLACE INTO classifications SELECT * FROM source_
{
idx
}
.classifications;
"
,
]
for
statement
in
statements
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_merge.py
+
12
−
0
View file @
3e610b20
...
...
@@ -5,7 +5,9 @@ import pytest
from
arkindex_worker.cache
import
(
MODELS
,
CachedClassification
,
CachedElement
,
CachedImage
,
CachedTranscription
,
merge_parents_cache
,
)
...
...
@@ -76,8 +78,10 @@ def test_merge_databases(
# We always start with an empty database
with
mock_databases
[
"
target
"
][
"
db
"
].
bind_ctx
(
MODELS
):
assert
CachedImage
.
select
().
count
()
==
0
assert
CachedElement
.
select
().
count
()
==
0
assert
CachedTranscription
.
select
().
count
()
==
0
assert
CachedClassification
.
select
().
count
()
==
0
# Merge all requested parents databases into our target
merge_parents_cache
(
...
...
@@ -88,8 +92,10 @@ def test_merge_databases(
# The target now should have the expected elements and transcriptions
with
mock_databases
[
"
target
"
][
"
db
"
].
bind_ctx
(
MODELS
):
assert
CachedImage
.
select
().
count
()
==
0
assert
CachedElement
.
select
().
count
()
==
len
(
expected_elements
)
assert
CachedTranscription
.
select
().
count
()
==
len
(
expected_transcriptions
)
assert
CachedClassification
.
select
().
count
()
==
0
assert
[
e
.
id
for
e
in
CachedElement
.
select
().
order_by
(
"
id
"
)
]
==
expected_elements
...
...
@@ -124,8 +130,10 @@ def test_merge_chunk(mock_databases, tmpdir, monkeypatch):
# The target should now have 3 elements and 0 transcription
with
mock_databases
[
"
target
"
][
"
db
"
].
bind_ctx
(
MODELS
):
assert
CachedImage
.
select
().
count
()
==
0
assert
CachedElement
.
select
().
count
()
==
3
assert
CachedTranscription
.
select
().
count
()
==
0
assert
CachedClassification
.
select
().
count
()
==
0
assert
[
e
.
id
for
e
in
CachedElement
.
select
().
order_by
(
"
id
"
)]
==
[
UUID
(
"
42424242-4242-4242-4242-424242424242
"
),
UUID
(
"
12341234-1234-1234-1234-123412341234
"
),
...
...
@@ -147,8 +155,10 @@ def test_merge_from_worker(
)
# At first we have no data in our main database
assert
CachedImage
.
select
().
count
()
==
0
assert
CachedElement
.
select
().
count
()
==
0
assert
CachedTranscription
.
select
().
count
()
==
0
assert
CachedClassification
.
select
().
count
()
==
0
# Configure worker with a specific data directory
monkeypatch
.
setenv
(
"
PONOS_DATA
"
,
str
(
tmpdir
))
...
...
@@ -157,8 +167,10 @@ def test_merge_from_worker(
mock_base_worker_with_cache
.
configure
()
# Then we have 2 elements and a transcription
assert
CachedImage
.
select
().
count
()
==
0
assert
CachedElement
.
select
().
count
()
==
3
assert
CachedTranscription
.
select
().
count
()
==
1
assert
CachedClassification
.
select
().
count
()
==
0
assert
[
e
.
id
for
e
in
CachedElement
.
select
().
order_by
(
"
id
"
)]
==
[
UUID
(
"
12341234-1234-1234-1234-123412341234
"
),
UUID
(
"
56785678-5678-5678-5678-567856785678
"
),
...
...
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