mirror of
https://github.com/wekan/wekan.git
synced 2026-03-07 06:10:15 +01:00
Replace konecty:mongo-counter with inline implementation
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.
This commit is contained in:
parent
ff7729fc35
commit
3ebeac6b30
5 changed files with 30 additions and 4 deletions
|
|
@ -1 +1,25 @@
|
|||
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 };
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { incrementCounter } from './counters';
|
||||
|
||||
OrgUser = new Mongo.Collection('orgUser');
|
||||
|
||||
/**
|
||||
|
|
@ -14,7 +16,7 @@ OrgUser.attachSchema(
|
|||
// eslint-disable-next-line consistent-return
|
||||
autoValue() {
|
||||
if (this.isInsert && !this.isSet) {
|
||||
return incrementCounter('counters', 'orgUserId', 1);
|
||||
return incrementCounter('orgUserId', 1);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { incrementCounter } from './counters';
|
||||
|
||||
SessionData = new Mongo.Collection('sessiondata');
|
||||
|
||||
/**
|
||||
|
|
@ -14,7 +16,7 @@ SessionData.attachSchema(
|
|||
// eslint-disable-next-line consistent-return
|
||||
autoValue() {
|
||||
if (this.isInsert && !this.isSet) {
|
||||
return incrementCounter('counters', 'orgId', 1);
|
||||
return incrementCounter('orgId', 1);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue