Skip to content

Instantly share code, notes, and snippets.

@williscool
Forked from Slokh/script.py
Created January 24, 2022 22:02
Show Gist options
  • Save williscool/cfbcf7967d2a4501836d8c1c81062f0c to your computer and use it in GitHub Desktop.
Save williscool/cfbcf7967d2a4501836d8c1c81062f0c to your computer and use it in GitHub Desktop.
from api.lib.tasks.index_objects import index_objects
from api.lib.utils.list_utils import chunks
from api.lib.utils import get_logger
logger = get_logger()
start = datetime(2021, 11, 30, 17, 0)
end = datetime(2021, 11, 30, 17, 50)
asset_ids_created = AssetEvent.objects.using(settings.DB_REPLICA_LONG_QUERIES).filter(event_timestamp__gte=start, event_timestamp__lte=end, event_type="created").order_by('total_price').values('asset_id').distinct()
asset_ids_others = AssetEvent.objects.using(settings.DB_REPLICA_LONG_QUERIES).filter(event_timestamp__gte=start, event_timestamp__lte=end).exclude(event_type="created").values('asset_id').distinct()
ids = [asset_id['asset_id'] for asset_id in asset_ids_created] + [asset_id['asset_id'] for asset_id in asset_ids_others]
for i, chunk in enumerate(chunks(ids, 25)):
if i % 1000 == 0:
logger.info(f"Indexing chunk starting {i}")
index_objects.apply_async(kwargs=dict(model_name="Asset", object_pks=chunk), queue="index_collection")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment