This commit is contained in:
		
							parent
							
								
									cef55a78c9
								
							
						
					
					
						commit
						8059f6f224
					
				@ -1562,49 +1562,11 @@ export const syncWorldState = async (): Promise<void> => {
 | 
				
			|||||||
        logger.warn(`Unknown action ${action} for field ${name} in world state sync`);
 | 
					        logger.warn(`Unknown action ${action} for field ${name} in world state sync`);
 | 
				
			||||||
        continue;
 | 
					        continue;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    let nextSync = Number.MAX_SAFE_INTEGER;
 | 
					 | 
				
			||||||
    if (interval && interval > 0) {
 | 
					    if (interval && interval > 0) {
 | 
				
			||||||
        nextSync = Date.now() + interval * 1000; // Convert seconds to milliseconds
 | 
					        logger.info(`Next world state sync in ${interval} seconds`);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    for (const key in fields) {
 | 
					 | 
				
			||||||
        switch (key) {
 | 
					 | 
				
			||||||
            case "VoidTraders":
 | 
					 | 
				
			||||||
            case "Invasions":
 | 
					 | 
				
			||||||
            case "SyndicateMissions":
 | 
					 | 
				
			||||||
            case "ActiveMissions":
 | 
					 | 
				
			||||||
            case "NodeOverrides":
 | 
					 | 
				
			||||||
            case "PrimeVaultTraders":
 | 
					 | 
				
			||||||
            case "DailyDeals": {
 | 
					 | 
				
			||||||
                if (Array.isArray(staticWorldState_[key])) {
 | 
					 | 
				
			||||||
                    const items = staticWorldState_[key] as (
 | 
					 | 
				
			||||||
                        | { Expiry?: { $date?: { $numberLong?: string } } }
 | 
					 | 
				
			||||||
                        | undefined
 | 
					 | 
				
			||||||
                    )[];
 | 
					 | 
				
			||||||
                    for (const item of items) {
 | 
					 | 
				
			||||||
                        const expire = item?.Expiry?.$date?.$numberLong;
 | 
					 | 
				
			||||||
                        if (typeof expire !== "string") continue;
 | 
					 | 
				
			||||||
                        const expireMs = parseInt(expire, 10);
 | 
					 | 
				
			||||||
                        if (isNaN(expireMs)) continue;
 | 
					 | 
				
			||||||
                        nextSync = Math.min(nextSync, expireMs);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    logger.info(`World state sync completed, next sync at ${nextSync}`);
 | 
					 | 
				
			||||||
    if (nextSync < Number.MAX_SAFE_INTEGER) {
 | 
					 | 
				
			||||||
        let nextSyncDelta = nextSync - Date.now();
 | 
					 | 
				
			||||||
        if (nextSyncDelta < 60 * 1000) {
 | 
					 | 
				
			||||||
            // Don't schedule syncs more often than once per minute
 | 
					 | 
				
			||||||
            logger.warn("Next world state sync is scheduled too soon, delaying it by 1 minute");
 | 
					 | 
				
			||||||
            nextSyncDelta = 60 * 1000;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            nextSyncDelta += 1000;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        logger.info(`Next world state sync in ${Math.round(nextSyncDelta / 1000)} seconds`);
 | 
					 | 
				
			||||||
        syncWorldStateTimer = setTimeout(() => {
 | 
					        syncWorldStateTimer = setTimeout(() => {
 | 
				
			||||||
            void syncWorldState();
 | 
					            void syncWorldState();
 | 
				
			||||||
        }, nextSyncDelta);
 | 
					        }, interval * 1000);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        logger.info("No next world state sync scheduled");
 | 
					        logger.info("No next world state sync scheduled");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user