Skip to content

Instantly share code, notes, and snippets.

@Slokh
Last active January 24, 2022 22:02
Show Gist options
  • Save Slokh/174f7fb77487ce80847ead84bad34f4b to your computer and use it in GitHub Desktop.
Save Slokh/174f7fb77487ce80847ead84bad34f4b 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