Skip to content
Snippets Groups Projects
Commit c16a32d3 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: add logging on inserts and updates

parent f326deec
No related branches found
No related tags found
2 merge requests!105REL: v0.4.0,!102MAINT: add logging on inserts and updates
Pipeline #33845 failed
...@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### ### Added ###
- DateElementConverter: allows to interpret text as a date object - DateElementConverter: allows to interpret text as a date object
- the restricted_path argument allows to crawl only a subtree - the restricted_path argument allows to crawl only a subtree
- logging that provides a summary of what is inserted and updated
### Changed ### ### Changed ###
......
...@@ -1017,20 +1017,25 @@ class Crawler(object): ...@@ -1017,20 +1017,25 @@ class Crawler(object):
referencing_entities) referencing_entities)
for record in to_be_updated] for record in to_be_updated]
# Merge with existing data to prevent unwanted overwrites # Merge with existing data to prevent unwanted overwrites
to_be_updated = self._merge_properties_from_remote(to_be_updated, to_be_updated = self._merge_properties_from_remote(to_be_updated, identified_records)
identified_records)
# remove unnecessary updates from list by comparing the target records # remove unnecessary updates from list by comparing the target records
# to the existing ones # to the existing ones
to_be_updated = self.remove_unnecessary_updates( to_be_updated = self.remove_unnecessary_updates(to_be_updated, identified_records)
to_be_updated, identified_records)
logger.info(f"Going to insert {len(to_be_inserted)} Entities:\n"
+ self.create_entity_summary(to_be_inserted))
logger.info(f"Going to update {len(to_be_inserted)} Entities:\n"
+ self.create_entity_summary(to_be_updated))
if commit_changes: if commit_changes:
self.execute_parent_updates_in_list(to_be_updated, securityMode=self.securityMode, self.execute_parent_updates_in_list(to_be_updated, securityMode=self.securityMode,
run_id=self.run_id, unique_names=unique_names) run_id=self.run_id, unique_names=unique_names)
logger.info(f"Added parent RecordTypes where necessary.")
self.execute_inserts_in_list( self.execute_inserts_in_list(
to_be_inserted, self.securityMode, self.run_id, unique_names=unique_names) to_be_inserted, self.securityMode, self.run_id, unique_names=unique_names)
logger.info(f"Executed inserts.")
self.execute_updates_in_list( self.execute_updates_in_list(
to_be_updated, self.securityMode, self.run_id, unique_names=unique_names) to_be_updated, self.securityMode, self.run_id, unique_names=unique_names)
logger.info(f"Executed updates.")
update_cache = UpdateCache() update_cache = UpdateCache()
pending_inserts = update_cache.get_inserts(self.run_id) pending_inserts = update_cache.get_inserts(self.run_id)
...@@ -1045,6 +1050,25 @@ class Crawler(object): ...@@ -1045,6 +1050,25 @@ class Crawler(object):
return (to_be_inserted, to_be_updated) return (to_be_inserted, to_be_updated)
@staticmethod
def create_entity_summary(entities: list[db.Entity]):
""" Creates a summary string reprensentation of a list of entities."""
parents = {}
for el in entities:
for pp in el.parents:
if pp.name not in parents:
parents[pp.name] = []
else:
parents[pp.name].append(el.id)
output = ""
for key, value in parents.items():
output += f"{key}:\n"
for el in value:
output += create_entity_link(el) + ", "
output = output[:-2] + "\n"
return output
@staticmethod @staticmethod
def inform_about_pending_changes(pending_changes, run_id, path, inserts=False): def inform_about_pending_changes(pending_changes, run_id, path, inserts=False):
# Sending an Email with a link to a form to authorize updates is # Sending an Email with a link to a form to authorize updates is
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment