using XFEEDToolBox.Core.Galaxy; namespace XFEEDToolBox.ViewModels; public partial class ToolboxViewModel { private (int ProcessId,long Epoch,long Address)? galaxyOverrideResolveCursor; private Task ResolvePublishedGalaxyOverridesAsync(GalaxyCatalogueSelection selection,NativeGalaxyCatalog native, Func currentSource,CancellationToken token)=> ResolvePublishedGalaxyOverridesAsync(selection,native.ProcessId,native.ResolveAddressAsync,currentSource,token); private async Task ResolvePublishedGalaxyOverridesAsync(GalaxyCatalogueSelection selection,int processId, Func> resolve,Func currentSource,CancellationToken token) { using var stop=CancellationTokenSource.CreateLinkedTokenSource(token,lifetime.Token); var previous=Interlocked.Exchange(ref galaxyOverrideResolveStop,stop); try{previous?.Cancel();}catch(ObjectDisposedException){} var epoch=Volatile.Read(ref galaxySourceEpoch);var view=Volatile.Read(ref galaxyViewVersion); try { // Let the initial cell request and the first visible frame proceed first. await Task.Yield(); if(selection.PointOverrides is not{} points||points.ProcessId!=processId)return; bool Latest()=>!stop.IsCancellationRequested&&epoch==Volatile.Read(ref galaxySourceEpoch)&& view==Volatile.Read(ref galaxyViewVersion)&¤tSource()&&ReferenceEquals(selection,GalaxyCatalogueSelection)&& ReferenceEquals(points,GalaxyCatalogueSelection?.PointOverrides); if(!Latest())return; var rows=points.Overrides.Values.Where(row=>row.Name is null).OrderBy(row=>row.SystemAddress).ToArray(); if(rows.Length==0)return; // Names are immutable catalogue facts. Index exact cached identities once, // rather than scanning the entire galaxy cache for every queued address. var cached=new HashSet(); foreach(var system in galaxyCache.Values) if(system.SystemAddress is{} address&&points.TryGetOverride(address,out var row)&&row?.Position==system.Position) cached.Add(address); var cursor=galaxyOverrideResolveCursor is{} old&&old.ProcessId==processId&&old.Epoch==epoch?old.Address:0; var start=Array.FindIndex(rows,row=>row.SystemAddress>cursor);if(start<0)start=0; var dirty=false;var published=false;var lastPublish=Environment.TickCount64; void Flush() { if(!dirty||!Latest())return; dirty=false;published=true;lastPublish=Environment.TickCount64; PublishGalaxy();if(Latest())QueueGalaxyFilterInformation(); } for(var index=0;index=100)Flush(); } } if((index+1)%32==0) { Flush();await Task.Yield(); } } Flush(); } catch(OperationCanceledException){} finally{Interlocked.CompareExchange(ref galaxyOverrideResolveStop,null,stop);} } }