Commit Graph
14 Commits
Author SHA1 Message Date
Andy Low 69b620dd2f Harden MongoDB driver compatibility 2026-04-19 23:24:22 +01:00
Ben WestandCopilot c6c60af906 Add array input tests for food API
- Add tests for POST with array of foods
- Add tests for PUT with array of foods
- Add test for empty array returning empty array
- Fix PUT endpoint to normalize array input like POST
- Fix food.save() storage to handle arrays with bulkWrite
- Rename test file to follow *.test.js convention

Validates fix from ef7bff3d for complete array handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-18 15:58:50 -07:00
Ben WestandCopilot 67d2099331 perf: optimize activity and food storage with bulkWrite
Replace sequential replaceOne calls with bulkWrite for batch upserts.
This improves performance when inserting multiple documents at once.

- activity.js: Use bulkWrite with replaceOne ops instead of forEach loop
- food.js: Same optimization for consistency

Both maintain exact same upsert behavior (query by _id+created_at or doc).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-18 14:49:25 -07:00
Ben WestandCopilot ef7bff3d53 fix(food): add array support to food API POST
Add array normalization to food API POST endpoint:
- API layer: normalize single object to array (like activity/profile)
- Storage layer: use replaceOne loop with upsert (same as activity pattern)
- Storage layer: accept both single object and array for backward compat

Previously POST /api/food/ with array input would crash:
  insertOne([{...}]) → MongoDB error

Now supports both single object and array input consistently.
Response format is now array (matching treatments pattern).

Fixes #8447

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-18 14:06:16 -07:00
Ben West 4914589557 adjust food api for updated mongo and add test 2026-01-19 13:13:48 -08:00
Ben West 1107e84a6e Revert "Revert "Merge pull request #8026 from nightscout/less_frequent_db_updates""
This reverts commit 2e65b1dd9b.
Try to bring back #8026.
2026-01-19 13:13:43 -08:00
Ben West 2e65b1dd9b Revert "Merge pull request #8026 from nightscout/less_frequent_db_updates"
This reverts commit 2757fe585d, reversing
changes made to 4a461e5890.
2023-10-19 13:03:38 -07:00
Sulka Haro 32163a0cd1 * Fix storage so tests pass with new Mongo driver
* Removes old openaps-storage feature
2023-06-01 22:45:07 +03:00
Sulka Haro 93ffb25147 Upgrade Mongo driver to latest legacy-API compatible version 2023-06-01 12:20:36 +03:00
Jeremy Cunningham abe8554aaa Make ObjectID initialization consistent 2018-11-20 22:19:25 -06:00
Jeremy Cunningham 140cc26705 Return error if insert fails for activity, devicestatus, or food. 2018-10-16 08:32:53 -05:00
Sulka HaroandJeremy Cunningham e622810094 Add error logging to all Mongo inserts 2018-10-16 08:00:20 -05:00
PiererGitandSulka Haro 1d59631818 fix food save (#3768)
2018-08-04T10:25:32.244096+00:00 app[web.1]: Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
2018-08-04T10:25:32.244099+00:00 app[web.1]:     at new ObjectID (/app/node_modules/bson/lib/bson/objectid.js:50:11)
2018-08-04T10:25:32.244101+00:00 app[web.1]:     at Function.save (/app/lib/server/food.js:14:15)
2018-08-04T10:25:32.244103+00:00 app[web.1]:     at /app/lib/api/food/index.js:59:18
2018-08-04T10:25:32.244105+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2018-08-04T10:25:32.244106+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/route.js:137:13)
2018-08-04T10:25:32.244107+00:00 app[web.1]:     at check (/app/lib/authorization/index.js:182:9)
2018-08-04T10:25:32.244109+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2018-08-04T10:25:32.244110+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/route.js:137:13)
2018-08-04T10:25:32.244111+00:00 app[web.1]:     at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2018-08-04T10:25:32.244113+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2018-08-04T10:25:32.249694+00:00 heroku[router]: at=info method=PUT path="/api/v1/food/" host=xxx.herokuapp.com request_id=yyy fwd="zzz" dyno=web.1 connect=0ms service=20ms status=500 bytes=1026 protocol=https
2018-08-05 12:02:23 +03:00
Sulka Haro 051576056a Moved server-specific sources to their own folder. Removed some unused code as per Codacy reports 2017-12-28 19:15:52 +02:00