Skip to content

Commit

Permalink
improve nesting, logging
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Dec 10, 2024
1 parent 0674e12 commit e7a62a1
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions api/edge_api/management/commands/ensure_identity_traits_blanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,39 @@
identity_wrapper = DynamoIdentityWrapper()


LOG_COUNT_EVERY = 100_000


logger = logging.getLogger(__name__)


class Command(BaseCommand):
def handle(self, *args: Any, **options: Any) -> None:
total_count = identity_wrapper.table.item_count
scanned_count = 0

for identity_document in identity_wrapper.query_get_all_items():
should_write_identity_document = False

if identity_traits_data := identity_document.get("identity_traits"):
for trait_data in identity_traits_data:
if "trait_value" not in trait_data:
should_write_identity_document = True
trait_data["trait_value"] = ""
blank_traits = (
trait_data
for trait_data in identity_traits_data
if "trait_value" not in trait_data
)
for trait_data in blank_traits:
should_write_identity_document = True
trait_data["trait_value"] = ""

if should_write_identity_document:
identity_wrapper.put_item(identity_document)
self.stdout.write(
f"Fixed identity id={identity_document['identity_uuid']}",
f"fixed identity scanned={scanned_count}/{total_count} id={identity_document['identity_uuid']}",
)

scanned_count += 1
if not (scanned_count % LOG_COUNT_EVERY):
self.stdout.write(
f"scanned={scanned_count}/{total_count} percentage={scanned_count/total_count*100:.2f}"
)
self.stdout.write(self.style.SUCCESS("Finished."))

0 comments on commit e7a62a1

Please sign in to comment.