mirror of
https://github.com/wekan/wekan.git
synced 2026-03-07 14:20:15 +01:00
Remove the konecty:mongo-counter Meteor package dependency and replace it with a minimal inline incrementCounter function using raw MongoDB findOneAndUpdate. Also exports an async version for future Meteor 3.0 migration. No data migration needed — uses the same next_val field.
25 lines
795 B
JavaScript
25 lines
795 B
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
|
|
Counters = new Mongo.Collection('counters');
|
|
|
|
// Async version (for future Meteor 3.0 migration)
|
|
async function incrementCounterAsync(counterName, amount = 1) {
|
|
const result = await Counters.rawCollection().findOneAndUpdate(
|
|
{ _id: counterName },
|
|
{ $inc: { next_val: amount } },
|
|
{ upsert: true, returnDocument: 'after' },
|
|
);
|
|
return result.value ? result.value.next_val : result.next_val;
|
|
}
|
|
|
|
// Sync version (for Meteor 2.x autoValue compatibility)
|
|
const incrementCounter = Meteor.wrapAsync(async (counterName, amount, callback) => {
|
|
try {
|
|
const result = await incrementCounterAsync(counterName, amount);
|
|
callback(null, result);
|
|
} catch (err) {
|
|
callback(err);
|
|
}
|
|
});
|
|
|
|
export { incrementCounter, incrementCounterAsync };
|