Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve efficiency when reporting existing objects #42

Merged
merged 6 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 42 additions & 48 deletions karton/mwdb_reporter/mwdb_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,63 +219,57 @@ def _upload_object(
# Filter out 'karton' attribute which should not be reuploaded
attributes = {k: v for k, v in attributes.items() if k != "karton"}

if not existing_object:
if self.mwdb.api.supports_version("2.6.0"):
mwdb_object = object_uploader(
**object_params,
parent=parent,
tags=tags,
attributes=attributes,
karton_id=karton_id
)

if parent:
metadata.append("parent: " + parent.id)
if tags:
metadata.append("tags: " + ",".join(tags))
if attributes:
metadata.append("attributes: " + ",".join(attributes.keys()))
if not metadata:
metadata_info = "no metadata"
else:
metadata_info = "including " + "; ".join(metadata)
self.log.info(
"[%s %s] Uploaded object %s",
mwdb_object.TYPE,
mwdb_object.id,
metadata_info,
)
else:
# 2.0.0+ Backwards compatible version
if self.mwdb.api.supports_version("2.6.0"):
mwdb_object = object_uploader(
**object_params,
parent=parent,
tags=tags,
attributes=attributes,
karton_id=karton_id,
)
else:
# 2.0.0+ Backwards compatible version
if not existing_object:
mwdb_object = object_uploader(
**object_params, parent=parent, metakeys={"karton": karton_id}
)
if parent:
metadata.append("parent: " + parent.id)
if not metadata:
metadata_info = "no metadata"
else:
metadata_info = "including " + "; ".join(metadata)
self.log.info(
"[%s %s] Uploaded object %s",
mwdb_object.TYPE,
mwdb_object.id,
metadata_info,
)
self._add_tags(mwdb_object, tags)
self._add_attributes(mwdb_object, attributes)
self._add_comments(mwdb_object, comments)
else:
mwdb_object = existing_object
self._add_parent(mwdb_object, parent)
else:
mwdb_object = existing_object
self._add_parent(mwdb_object, parent)

self._add_tags(mwdb_object, tags)
self._add_attributes(mwdb_object, attributes)
self._add_comments(mwdb_object, comments)

self._add_comments(mwdb_object, comments)

if parent:
metadata.append("parent: " + parent.id)
if tags:
metadata.append("tags: " + ",".join(tags))
if attributes:
metadata.append("attributes: " + ",".join(attributes.keys()))
if comments:
metadata.append(f"comments: {len(comments)}")
if not metadata:
metadata_info = "(no metadata)"
else:
metadata_info = "including " + "; ".join(metadata)

if existing_object:
self.log.info(
"[%s %s] Uploaded object %s",
mwdb_object.TYPE,
mwdb_object.id,
metadata_info,
)
else:
self.log.info(
"[%s %s] Added metadata to existing object",
"[%s %s] Added metadata to existing object %s",
mwdb_object.TYPE,
mwdb_object.id,
metadata_info,
)

return not existing_object, mwdb_object

def _upload_file(
Expand Down
Loading