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
|
|
@ -29,40 +29,41 @@ const findFiresInRegion = (zone) => {
|
|||
return result;
|
||||
};
|
||||
|
||||
export const countRealFires = (firesCursor) => {
|
||||
export const countRealFires = async (firesCursor) => {
|
||||
const realFires = [];
|
||||
firesCursor.forEach((fire) => {
|
||||
const fires = Array.isArray(firesCursor) ? firesCursor : await firesCursor.fetchAsync();
|
||||
for (const fire of fires) {
|
||||
if (debug) console.log(`${JSON.stringify(fire)} -----`);
|
||||
const union = firesUnion([fire]);
|
||||
const union = await firesUnion([fire]);
|
||||
if (debug) console.log(`${JSON.stringify(union)} -----`);
|
||||
const falsePos = whichAreFalsePositives(FalsePositives, union);
|
||||
const industries = whichAreFalsePositives(Industries, union);
|
||||
if (falsePos.count() === 0 && industries.count() === 0) {
|
||||
if (await falsePos.countAsync() === 0 && await industries.countAsync() === 0) {
|
||||
realFires.push(fire);
|
||||
}
|
||||
});
|
||||
}
|
||||
// group fires
|
||||
const realUnion = firesUnion(realFires);
|
||||
const realUnion = await firesUnion(realFires);
|
||||
const unionCount = realUnion[0] &&
|
||||
realUnion[0].geometry &&
|
||||
realUnion[0].geometry.coordinates ? realUnion[0].geometry.coordinates.length : 0;
|
||||
return unionCount;
|
||||
};
|
||||
|
||||
const countFiresInRegions = (regions, stringsToRemove) => {
|
||||
const countFiresInRegions = async (regions, stringsToRemove) => {
|
||||
let total = 0;
|
||||
const fireStats = {};
|
||||
|
||||
regions.features.forEach((region) => {
|
||||
for (const region of regions.features) {
|
||||
const regionName = cleanProv(region.properties.name, stringsToRemove);
|
||||
const regionCode = region.properties.iso_a2;
|
||||
if (debug) console.log(`${regionName} -----`);
|
||||
try {
|
||||
const fires = findFiresInRegion(region);
|
||||
// TODO Also check neighbour fires (when better implementation of that part)
|
||||
const initialCount = fires.count();
|
||||
const initialCount = await fires.countAsync();
|
||||
if (initialCount > 0) {
|
||||
const unionCount = countRealFires(fires);
|
||||
const unionCount = await countRealFires(fires);
|
||||
if (debug) console.log(`${regionName} initial: ${initialCount}, union calc: ${unionCount}`);
|
||||
if (unionCount > 0) {
|
||||
total += unionCount;
|
||||
|
|
@ -72,7 +73,7 @@ const countFiresInRegions = (regions, stringsToRemove) => {
|
|||
} catch (e) {
|
||||
ravenLogger.log(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
return { total, fires: fireStats };
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue