Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
timeout-minutes: 10
services:
mongodb:
image: mongo:6
image: mongo:8
ports:
- 27017:27017
strategy:
Expand All @@ -50,7 +50,7 @@ jobs:
timeout-minutes: 10
services:
mongodb:
image: mongo:6
image: mongo:8
ports:
- 27017:27017
strategy:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 13 additions & 2 deletions lib/meters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down