Skip to content

Commit ef15724

Browse files
committed
clear enriched at for property clearing
1 parent d0d09a3 commit ef15724

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

poliloom/poliloom/cli.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,38 @@ def clean_properties(dry_run):
835835
click.echo(
836836
f" • [DRY RUN] Would delete {count_query} unevaluated extracted properties"
837837
)
838+
# Count affected politicians
839+
affected_politicians = (
840+
session.query(Property.politician_id)
841+
.filter(
842+
Property.archived_page_id.isnot(None),
843+
Property.statement_id.is_(None),
844+
Property.deleted_at.is_(None),
845+
~has_evaluation,
846+
)
847+
.distinct()
848+
.count()
849+
)
850+
click.echo(
851+
f" • [DRY RUN] Would clear enriched_at for {affected_politicians} politicians"
852+
)
838853
else:
854+
from poliloom.models import Politician
855+
856+
# Get affected politician IDs before deleting properties
857+
affected_politician_ids = [
858+
row[0]
859+
for row in session.query(Property.politician_id)
860+
.filter(
861+
Property.archived_page_id.isnot(None),
862+
Property.statement_id.is_(None),
863+
Property.deleted_at.is_(None),
864+
~has_evaluation,
865+
)
866+
.distinct()
867+
.all()
868+
]
869+
839870
# Delete properties without evaluations
840871
deleted_count = (
841872
session.query(Property)
@@ -849,10 +880,19 @@ def clean_properties(dry_run):
849880
)
850881
.delete(synchronize_session=False)
851882
)
883+
884+
# Clear enriched_at for affected politicians
885+
cleared_count = (
886+
session.query(Politician)
887+
.filter(Politician.id.in_(affected_politician_ids))
888+
.update({Politician.enriched_at: None}, synchronize_session=False)
889+
)
890+
852891
session.commit()
853892
click.echo(
854893
f"✅ Successfully deleted {deleted_count} unevaluated extracted properties"
855894
)
895+
click.echo(f"✅ Cleared enriched_at for {cleared_count} politicians")
856896

857897
except Exception as e:
858898
session.rollback()

0 commit comments

Comments
 (0)