only log a message if there are event cache entries, and formatting

This commit is contained in:
Adam 2022-02-25 21:44:13 +01:00
parent 93e02e852a
commit 758fea4195
2 changed files with 17 additions and 15 deletions

View file

@ -16,7 +16,6 @@ export namespace EventDataCache {
if (force == true || isAnythingUndefined) {
log("Initialising global.cache")
// global.cache = new Map<CacheKey<FactorioEventUpdateType>, CacheEntry<FactorioEventUpdateType>>()
global.cache = new LuaTable<string, CacheEntry<FactorioEventUpdateType>>()
log("Initialising global.DEFAULT_CACHE_DURATION_TICKS")
@ -95,7 +94,9 @@ export namespace EventDataCache {
global.cache.delete(key)
}
}
log(`cache expired items count: ${countExpired}, total: ${countTotal}`)
if (countExpired + countTotal > 0) {
log(`cache expired items count: ${countExpired}, total: ${countTotal}`)
}
return expiredData
}
@ -130,7 +131,7 @@ export namespace EventDataCache {
}
// /** Map a {@link FactorioEventUpdateType} to a {@link FactorioEventUpdate} DTO */
/** Map a {@link FactorioEventUpdateType} to a {@link FactorioEventUpdate} DTO */
type ConvertToUpdate<TYPE extends FactorioEventUpdateType> =
TYPE extends "PLAYER" ? PlayerUpdate :
TYPE extends "MAP_CHUNK" ? MapChunkUpdate :
@ -138,6 +139,7 @@ export namespace EventDataCache {
never
/** Map a {@link FactorioEventUpdateType} to a {@link FactorioEventUpdateKey} */
type ConvertToUpdateKey<TYPE extends FactorioEventUpdateType> =
TYPE extends "PLAYER" ? PlayerUpdateKey :
TYPE extends "MAP_CHUNK" ? MapChunkUpdateKey :
@ -151,7 +153,7 @@ export namespace EventDataCache {
& Omit<ConvertToUpdateKey<TYPE>, "updateType">
/** Make nullable-fields optional, and `updateType` specific */
/** Make `updateType` specific */
export type CacheData<TYPE extends FactorioEventUpdateType> =
CacheTyped<TYPE>
& Omit<ConvertToUpdate<TYPE>, "updateType">
@ -205,11 +207,11 @@ export namespace EventDataCache {
}
function isKeyInstanceOf<TYPE extends FactorioEventUpdateType>(
key: CacheKey<any> | undefined,
updateType: TYPE,
): key is CacheKey<TYPE> {
return key != undefined && key.updateType == updateType
}
// function isKeyInstanceOf<TYPE extends FactorioEventUpdateType>(
// key: CacheKey<any> | undefined,
// updateType: TYPE,
// ): key is CacheKey<TYPE> {
// return key != undefined && key.updateType == updateType
// }
}

View file

@ -24,7 +24,7 @@ class FactorioEventUpdatePacket(
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
sealed interface FactorioEventUpdateKey {
@ -83,7 +83,7 @@ sealed class FactorioEventUpdate : FactorioEventUpdateKey {
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
sealed interface PlayerUpdateKey : FactorioEventUpdateKey {
@ -128,7 +128,7 @@ data class PlayerUpdate(
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
sealed interface EntityUpdateKey : EntityIdentifiers, FactorioEventUpdateKey {
@ -163,7 +163,7 @@ data class EntityUpdate(
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
sealed interface MapChunkUpdateKey : FactorioEventUpdateKey {
@ -195,4 +195,4 @@ data class MapChunkUpdate(
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */