Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Adjust lastship precache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan-LS committed Jan 17, 2022
1 parent 0732830 commit 938359f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class CharacterNameToID(AbstractMultiEndpoint):
@staticmethod
def default_ttl() -> int:
return 172800 # 2 days
return 1296000 # 15 days

@staticmethod
def _get_unprefixed_key_hash_sync(query_item: str, **kwargs):
Expand All @@ -35,14 +35,14 @@ def _make_dict(self, query_name: str, row_character_name: tb_characters):
"id": row_character_name.character_id,
"found": True
}
self.set_min_ttl(d, self.default_ttl())
self.set_min_ttl(d, self.default_ttl()) # default ttl for known char
else:
d["data"] = {
"name": query_name,
"id": None,
"found": False
}
self.set_min_ttl(d, 10800) # 3 hours
self.set_min_ttl(d, 10800) # 3 hours for unknown char
return d

def _do_endpoint_logic_sync(self, lookup_dict: dict, **kwargs) -> dict:
Expand Down
6 changes: 3 additions & 3 deletions Insight/InsightSubsystems/Cache/CacheEndpoint/LastShip.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, cache_manager):
883 # cap industrial
]
super().__init__(cache_manager)
self.precache: bool = self.config.get("SUBSYSTEM_CACHE_LASTSHIP_PRECACHE")
self.precache: int = self.config.get("SUBSYSTEM_CACHE_LASTSHIP_PRECACHE_SECONDS")
self.lock_char_ids_recent_activity = asyncio.Lock(loop=self.loop)
self.char_ids_recent_activity = set()
self.ttl = self.config.get("SUBSYSTEM_CACHE_LASTSHIP_TTL")
Expand Down Expand Up @@ -243,10 +243,10 @@ def _extract_characters(self, new_km: tb_kills):

async def cron_precache_operation(self):
async with self.lock_char_ids_recent_activity:
if not self.precache:
if self.precache <= 0: # disabled
self.char_ids_recent_activity = set()
return
if len(self.char_ids_recent_activity) > 0:
self.lg.info("Starting precache of {} character IDs.".format(len(self.char_ids_recent_activity)))
old_set = self.char_ids_recent_activity
self.char_ids_recent_activity = set()
await self.get(char_ids=old_set) # safe for set does not have to be list
Expand Down
5 changes: 4 additions & 1 deletion Insight/InsightSubsystems/Cron/CronTasks/LastShipPreCache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ class LastShipPreCache(AbstractCronTask):
def __init__(self, cron_manager):
super().__init__(cron_manager)
self.LastShip: LastShip = LastShip()
self._loop_iteration_override = max(60, self.service.config.get("SUBSYSTEM_CACHE_LASTSHIP_PRECACHE_SECONDS"))
if self.service.config.get("SUBSYSTEM_CACHE_LASTSHIP_PRECACHE_SECONDS") > 0:
print("LastShip precache is enabled and is scheduled to run every {} seconds.".format(self._loop_iteration_override))

def loop_iteration(self) -> int:
return 60
return self._loop_iteration_override

async def _run_task(self):
await self.LastShip.cron_precache_operation()
2 changes: 1 addition & 1 deletion Insight/InsightUtilities/ConfigLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _load_all_options(self):
self.parse_int("POSTGRES_POOLSIZE", "NULL", "NULL", fail_if_empty=False, fallback_val=25, nonotify=True)
self.parse_int("POSTGRES_POOLOVERFLOW", "NULL", "NULL", fail_if_empty=False, fallback_val=10, nonotify=True)
self.parse_int("SUBSYSTEM_CACHE_THREADS", "NULL", "NULL", False, 8, True)
self.parse_bool("SUBSYSTEM_CACHE_LASTSHIP_PRECACHE", "NULL", "NULL", False, "FALSE", True)
self.parse_int("SUBSYSTEM_CACHE_LASTSHIP_PRECACHE_SECONDS", "NULL", "NULL", False, -1, True)
self.parse_int("SUBSYSTEM_CACHE_LASTSHIP_TTL", "NULL", "NULL", False, 7200, True)
self.parse_int("CRON_SYNCCONTACTS", "NULL", "NULL", False, 32400, True)
self.parse_list("INSIGHT_ADMINS", "NULL", "NULL", False, "", False)
Expand Down
2 changes: 1 addition & 1 deletion scripts/Docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ENV REDIS_SSL=""
ENV POSTGRES_POOLSIZE=""
ENV POSTGRES_POOLOVERFLOW=""
ENV SUBSYSTEM_CACHE_THREADS=""
ENV SUBSYSTEM_CACHE_LASTSHIP_PRECACHE=""
ENV SUBSYSTEM_CACHE_LASTSHIP_PRECACHE_SECONDS=""
ENV SUBSYSTEM_CACHE_LASTSHIP_TTL=""
ENV CRON_SYNCCONTACTS=""
ENV INSIGHT_ADMINS=""
Expand Down

0 comments on commit 938359f

Please sign in to comment.