diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 63b1ad5..62f5daa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: timeout-minutes: 10 services: mongodb: - image: mongo:6 + image: mongo:8 ports: - 27017:27017 strategy: @@ -50,7 +50,7 @@ jobs: timeout-minutes: 10 services: mongodb: - image: mongo:6 + image: mongo:8 ports: - 27017:27017 strategy: diff --git a/CHANGELOG.md b/CHANGELOG.md index eee2e44..b633607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # bedrock-meter-usage-reporter ChangeLog +## 10.1.0 - 2025-mm-dd + +### Changed +- Replace `lodash.shuffle` with local shuffle implementation. + ## 10.0.0 - 2025-03-07 ### Changed diff --git a/lib/meters.js b/lib/meters.js index 6c7671d..d9a38ab 100644 --- a/lib/meters.js +++ b/lib/meters.js @@ -11,7 +11,6 @@ import {httpsAgent} from '@bedrock/https-agent'; import {logger} from './logger.js'; import {OperationUsageCache} from './OperationUsageCache.js'; import {rangeDelay} from 'delay'; -import shuffle from 'lodash.shuffle'; import {ZcapClient} from '@digitalbazaar/ezcap'; const {config, util: {BedrockError}} = bedrock; @@ -285,7 +284,7 @@ export async function reportEligibleSample({signal} = {}) { because then a single process would mark all meters. */ const [touched, stale] = await Promise.all([getTouched(), getStale()]); const eligibleCount = touched.length + stale.length; - const categories = [shuffle(touched), shuffle(stale)]; + const categories = [_shuffle(touched), _shuffle(stale)]; // report on both touched and stale categories concurrently await Promise.all(categories.map( @@ -534,3 +533,15 @@ export function _getZcapClients() { export function resetAggregrators() { AGGREGATORS = new Map(); } + +function _shuffle(array) { + // create shallow copy first + array = array.slice(); + for(let i = array.length - 1; i > 0; --i) { + // get a random index from the remaining elements + const r = Math.floor(Math.random() * (i + 1)); + // swap elements + [array[i], array[r]] = [array[r], array[i]]; + } + return array; +} diff --git a/package.json b/package.json index a08007b..78e0ed4 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,7 @@ "@digitalbazaar/ezcap": "^4.1.0", "abort-controller": "^3.0.0", "assert-plus": "^1.0.0", - "delay": "^6.0.0", - "lodash.shuffle": "^4.2.0" + "delay": "^6.0.0" }, "peerDependencies": { "@bedrock/app-identity": "^4.0.0",