Skip to content

Commit

Permalink
Merge pull request #34747 from dimagi/gh/ucr/rebuild-once
Browse files Browse the repository at this point in the history
Improve rebuild_tables_by_domain command
  • Loading branch information
gherceg authored Jan 6, 2025
2 parents 11c3fce + 8cc6e50 commit d4f6396
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ def add_arguments(self, parser):
'--initiated-by', required=True, action='store',
dest='initiated', help='Who initiated the rebuild'
)
parser.add_argument("--async", action="store_true", dest="async", help="Run on celery")

def handle(self, domain, **options):
tables = StaticDataSourceConfiguration.by_domain(domain)
tables.extend(DataSourceConfiguration.by_domain(domain))
tables_by_id = {table.table_id: table for table in tables}

print("Rebuilding {} tables".format(len(tables)))
print("Rebuilding {} tables".format(len(tables_by_id)))

for table in tables:
tasks.rebuild_indicators(
table._id, initiated_by=options['initiated'], source='rebuild_tables_by_domain'
)
for table in tables_by_id.values():
if options['async']:
tasks.rebuild_indicators.delay(
table._id, initiated_by=options['initiated'], source='rebuild_tables_by_domain'
)
else:
tasks.rebuild_indicators(
table._id, initiated_by=options['initiated'], source='rebuild_tables_by_domain'
)

0 comments on commit d4f6396

Please sign in to comment.