Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
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
Code review analytics
Issue 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
caosdb
Software
CaosDB Crawler
Commits
92b6f9d6
Commit
92b6f9d6
authored
2 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: refactor bend_references and use merge_entities directly
parent
810445d1
Branches
Branches containing commit
Tags
Tags containing commit
3 merge requests
!71
REL: RElease v0.2.0
,
!56
F refactor
,
!5
FIX: use identifiable instead of record
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caoscrawler/crawl.py
+20
-23
20 additions, 23 deletions
src/caoscrawler/crawl.py
with
20 additions
and
23 deletions
src/caoscrawler/crawl.py
+
20
−
23
View file @
92b6f9d6
...
...
@@ -633,12 +633,21 @@ class Crawler(object):
identifiable
=
record
self
.
identified_cache
.
add
(
identifiable
=
identifiable
,
record
=
record
)
def
copy_attributes
(
self
,
fro
:
db
.
Entity
,
to
:
db
.
Entity
):
"""
Copy all attributes from one entity to another entity.
@staticmethod
def
bend_references_to_new_object
(
old
,
new
,
entities
):
"""
Bend references to the other object
Iterate over all entities in `entities` and check the values of all properties of
occurances of old Entity and replace them with new Entity
"""
merge_entities
(
to
,
fro
)
for
el
in
entities
:
for
p
in
el
.
properties
:
if
isinstance
(
p
.
value
,
list
):
for
index
,
val
in
enumerate
(
p
.
value
):
if
val
is
old
:
p
.
value
[
index
]
=
new
else
:
if
p
.
value
is
old
:
p
.
value
=
new
def
split_into_inserts_and_updates
(
self
,
ent_list
:
List
[
db
.
Entity
]):
if
self
.
identifiableAdapter
is
None
:
...
...
@@ -668,24 +677,12 @@ class Crawler(object):
"
are removed from the list
"
)
# Check the local cache first for duplicate
elif
self
.
get_identified_record_from_local_cache
(
record
)
is
not
None
:
# This record is a duplicate that can be removed. Make sure we do not lose
# information
# Update an (local) identified record that will be inserted
newrecord
=
self
.
get_identified_record_from_local_cache
(
record
)
self
.
copy_attributes
(
fro
=
record
,
to
=
newrecord
)
# Bend references to the other object
# TODO refactor this
for
el
in
flat
+
to_be_inserted
+
to_be_updated
:
for
p
in
el
.
properties
:
if
isinstance
(
p
.
value
,
list
):
for
index
,
val
in
enumerate
(
p
.
value
):
if
val
is
record
:
p
.
value
[
index
]
=
newrecord
else
:
if
p
.
value
is
record
:
p
.
value
=
newrecord
# This record is a duplicate that can be removed.
# We merge the two in order to prevent loss of information
newrecord
=
self
.
get_identified_record_from_local_cache
(
record
)
merge_entities
(
newrecord
,
record
)
Crawler
.
bend_references_to_new_object
(
old
=
record
,
new
=
newrecord
,
entities
=
flat
+
to_be_updated
+
to_be_inserted
)
del
flat
[
i
]
...
...
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