-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Heal all identities with blank traits (#4908)
- Loading branch information
Showing
5 changed files
with
286 additions
and
42 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
api/edge_api/management/commands/ensure_identity_traits_blanks.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from typing import Any | ||
|
||
from django.core.management import BaseCommand | ||
from structlog import get_logger | ||
from structlog.stdlib import BoundLogger | ||
|
||
from environments.dynamodb import DynamoIdentityWrapper | ||
|
||
identity_wrapper = DynamoIdentityWrapper() | ||
|
||
|
||
LOG_COUNT_EVERY = 100_000 | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args: Any, **options: Any) -> None: | ||
total_count = identity_wrapper.table.item_count | ||
scanned_count = 0 | ||
fixed_count = 0 | ||
|
||
log: BoundLogger = get_logger(total_count=total_count) | ||
log.info("started") | ||
|
||
for identity_document in identity_wrapper.query_get_all_items(): | ||
should_write_identity_document = False | ||
|
||
if identity_traits_data := identity_document.get("identity_traits"): | ||
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"] = "" | ||
|
||
scanned_count += 1 | ||
scanned_percentage = scanned_count / total_count * 100 | ||
|
||
if should_write_identity_document: | ||
identity_wrapper.put_item(identity_document) | ||
fixed_count += 1 | ||
|
||
log.info( | ||
"identity-fixed", | ||
identity_uuid=identity_document["identity_uuid"], | ||
scanned_count=scanned_count, | ||
scanned_percentage=scanned_percentage, | ||
fixed_count=fixed_count, | ||
) | ||
|
||
if not (scanned_count % LOG_COUNT_EVERY): | ||
log.info( | ||
"in-progress", | ||
scanned_count=scanned_count, | ||
scanned_percentage=scanned_percentage, | ||
fixed_count=fixed_count, | ||
) | ||
|
||
log.info( | ||
"finished", | ||
scanned_count=scanned_count, | ||
scanned_percentage=scanned_percentage, | ||
fixed_count=fixed_count, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.