Skip to content

Commit

Permalink
fix: foundry cron updates all characters
Browse files Browse the repository at this point in the history
  • Loading branch information
ishtanzar committed Mar 6, 2024
1 parent 4e485d0 commit eceaa23
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions wm-worker/src/services/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,32 @@ async def list_modified_characters(self, last_sync: str | int = None) -> list:
query_from = 0
query_size = 1000
last_sync_obj = arrow.get(last_sync) if last_sync else arrow.utcnow().shift(hours=-1)
index = self._ms.index('foundry_audit-' + last_sync_obj.strftime("%Y_%m"))

while True:
index = self._ms.index('foundry_audit-' + last_sync_obj.strftime("%Y_%m"))
resp = index.search('', {
'offset': query_from,
'limit': query_size,
'filter': "message = 'Actor modified' AND timestamp > " + str(last_sync_obj.int_timestamp)
})
self._logger.debug(f'ms.search {index.uid} - offset={query_from} limit={query_size} ts>{str(last_sync_obj.int_timestamp)}')

hits_count = 0
for h in resp['hits']:
hits_count += 1
modified.add(h['fields']['actor'])

if hits_count < query_size:
break

query_from = query_from + query_size
try:
hits_count = 0
ts = str(int(last_sync_obj.float_timestamp * 1000))

self._logger.debug(f'ms.search {index.uid} - offset={query_from} limit={query_size} ts>{ts}')

resp = index.search('', {
'offset': query_from,
'limit': query_size,
'filter': "message = 'Actor modified' AND timestamp > " + ts
})

for h in resp['hits']:
hits_count += 1
modified.add(h['fields']['actor'])

if hits_count < query_size:
break

query_from = query_from + query_size
except MeilisearchApiError as e:
self._logger.exception(f'Failed to query index: ' + e.message)
return []

self._logger.debug(f'Found {len(modified)} characters modified')
return list(modified)
Expand Down

0 comments on commit eceaa23

Please sign in to comment.