sliftutils 1.7.56 → 1.7.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -802,20 +802,22 @@ export class ArchivesChain implements IArchives {
802
802
  return urls[0];
803
803
  }
804
804
 
805
- /** Every URL that could serve this path, in source order: public sources matching both the path's route and the current valid window. Empty when none qualify. */
805
+ /** Every URL that could serve this path: public sources matching both the path's route and the current valid window. The first is the write node's (first matching source in config order, see runWrite - the one guaranteed current); the rest are ranked fastest-first by measured latency. Empty when none qualify. */
806
806
  public async getURLs(path: string): Promise<string[]> {
807
807
  let state = await this.getState();
808
808
  let route = getRoute(path);
809
- let providers: IArchives[] = [];
809
+ let candidates: { source: SourceWrapper; provider: IArchives }[] = [];
810
810
  for (let source of state.sources) {
811
811
  if (!(source.config.public ?? true)) continue;
812
812
  if (!routeContains(source.config.route, route)) continue;
813
813
  if (!configWindowCurrent(source.config)) continue;
814
814
  let provider = source.url || source.api;
815
815
  if (!provider) continue;
816
- providers.push(provider);
816
+ candidates.push({ source, provider });
817
817
  }
818
- let urls = await Promise.all(providers.map(provider => provider.getURL(path)));
818
+ let rest = candidates.slice(1);
819
+ sort(rest, x => x.source.getLatency());
820
+ let urls = await Promise.all([...candidates.slice(0, 1), ...rest].map(x => x.provider.getURL(path)));
819
821
  return [...new Set(urls)];
820
822
  }
821
823