meteor3: REST API async migration COMPLETE — smoke green on Meteor 3.1 + Mongo 7
All 12 Flutter REST endpoints byte-identical to the 1.6.1.1 baseline, running on Meteor 3.1 against dockerized MongoDB 7. The 3.x jump works end-to-end. - Rest.js: every endpoint action -> async; all Mongo calls -> *Async (findOneAsync/countAsync/fetchAsync/upsertAsync/removeAsync). - Helpers to async: countRealFires (accepts array|cursor, forEachAsync->for-of), firesUnion (fetchAsync), fireFromHash/findOrCreateFire (await, dropped Fibers Promise.await), subscriptionsInsert/subscriptionsRemove, upsertFalsePositive, falsePositives.insert, subscriptions.update method, countFiresInRegions. - getFires: countAsync() on a $near cursor throws on the mongodb 6 driver ($near not allowed in the aggregation countDocuments uses) -> fetch once and use array length for total. - Route order: json-routes 3.0 matches in registration order, so mobile/subscriptions/all/:token/:mobileToken is now registered BEFORE :token/:mobileToken/:subsId (else GET .../all/x/y hit the delete-only route).
This commit is contained in:
parent
b37069c3e5
commit
637a749e8d
6 changed files with 124 additions and 117 deletions
|
|
@ -53,12 +53,12 @@ const fixConfidence = (obj) => {
|
|||
return obj;
|
||||
};
|
||||
|
||||
const findOrCreateFire = (obj) => {
|
||||
const findOrCreateFire = async (obj) => {
|
||||
const fire = findFire(obj);
|
||||
// console.log(`Found: ${fire.count()}`);
|
||||
// console.log(`Found: ${await fire.countAsync()}`);
|
||||
if (!obj.address) {
|
||||
try {
|
||||
const rev = Promise.await(geocoder.reverse({ lat: obj.lat, lon: obj.lon }));
|
||||
const rev = await geocoder.reverse({ lat: obj.lat, lon: obj.lon });
|
||||
if (rev[0]) {
|
||||
obj.address = rev[0].formattedAddress;
|
||||
}
|
||||
|
|
@ -67,10 +67,10 @@ const findOrCreateFire = (obj) => {
|
|||
console.warn(reve);
|
||||
}
|
||||
}
|
||||
if (fire.count() === 0) {
|
||||
if (await fire.countAsync() === 0) {
|
||||
// const result =
|
||||
// console.log('Creating new fire');
|
||||
FiresCollection.upsert({ ourid: obj.ourid, when: obj.when, type: obj.type }, { $set: obj }, { multi: false, upsert: true });
|
||||
await FiresCollection.upsertAsync({ ourid: obj.ourid, when: obj.when, type: obj.type }, { $set: obj }, { multi: false, upsert: true });
|
||||
// console.log(JSON.stringify(result));
|
||||
}
|
||||
return findFire(obj);
|
||||
|
|
@ -139,13 +139,12 @@ function logUrl(fireEnc, params) {
|
|||
ravenLogger.log(message);
|
||||
}
|
||||
|
||||
export function fireFromHash(fireEnc, params) {
|
||||
export async function fireFromHash(fireEnc, params) {
|
||||
check(fireEnc, String);
|
||||
check(params, Object);
|
||||
|
||||
// console.log(fireEnc);
|
||||
// const unsealed = Promise.await(urlEnc.decrypt(fireEnc));
|
||||
const unsealed = Promise.await(unsealW(fireEnc));
|
||||
const unsealed = await unsealW(fireEnc);
|
||||
if (unsealed === undefined) {
|
||||
throw Error(`Fail to unseal '${fireEnc}'`);
|
||||
}
|
||||
|
|
@ -159,7 +158,7 @@ export function fireFromHash(fireEnc, params) {
|
|||
// FIXME:
|
||||
const unsealedFix = fixConfidence(unsealed);
|
||||
FiresCollection.schema.validate(unsealedFix);
|
||||
return findOrCreateFire(unsealedFix);
|
||||
return await findOrCreateFire(unsealedFix);
|
||||
/* console.log(`fires: ${fire.count()}`);
|
||||
* return fire; */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue