@le-space/core 0.6.42 → 0.6.43

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.
Files changed (2) hide show
  1. package/index.js +10 -1
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -256,6 +256,15 @@ function scoreSortedCrns(crns) {
256
256
  return leftName.localeCompare(rightName);
257
257
  });
258
258
  }
259
+ var TOP_CRN_POOL_SIZE = 5;
260
+ function shuffleTopPool(sorted, poolSize = TOP_CRN_POOL_SIZE) {
261
+ const pool = sorted.slice(0, poolSize);
262
+ for (let i = pool.length - 1; i > 0; i--) {
263
+ const j = Math.floor(Math.random() * (i + 1));
264
+ [pool[i], pool[j]] = [pool[j], pool[i]];
265
+ }
266
+ return [...pool, ...sorted.slice(poolSize)];
267
+ }
259
268
  function filterDeployableCrns(crns, options = {}) {
260
269
  return scoreSortedCrns(
261
270
  compatibleCrns(crns, options.excludedHashes).filter((crn) => hasCrnCapacity(crn, options.spec))
@@ -368,7 +377,7 @@ async function rankCandidateCrns(crns, options) {
368
377
  excludedHashes: options.excludedHashes
369
378
  });
370
379
  if (!preferredCountryCode || sortedCrns.length === 0) {
371
- return sortedCrns;
380
+ return shuffleTopPool(sortedCrns);
372
381
  }
373
382
  const enrichedTopCrns = await enrichCrnsWithGeo(sortedCrns.slice(0, geoLimit), options);
374
383
  const mergedByHash = new Map(enrichedTopCrns.map((crn) => [crn.hash, crn]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/core",
3
- "version": "0.6.42",
3
+ "version": "0.6.43",
4
4
  "description": "Reusable Aleph deployment, runtime, and guest lifecycle logic.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "url": "https://github.com/NiKrause/relay-button/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@le-space/aleph-bootstrap": "0.6.42",
28
- "@le-space/shared-types": "0.6.42"
27
+ "@le-space/aleph-bootstrap": "0.6.43",
28
+ "@le-space/shared-types": "0.6.43"
29
29
  }
30
30
  }