Food, sync and warmer updates from 2026-10-26
- Food: "All products" lists what's here first (My foods, the food database, kept products), then Open Food Facts; the start of a barcode (4+ digits) finds the products starting with it (dashboard, app, server search). - Food: My foods barcodes; entries follow edits of their food or meal, and meals made with a changed food are worked out again (nested meals too); a save that changes nothing isn't written. - Food: the week strip shows protein / carbs / fat per day, over-target calories in red; the header's arrows go by week, days swap in place with prefetch on hover; the app's arrows go by week, a sideways swipe by day. - Food search: stomach / žalúdok / pipotă find gizzards, kurací / pui chicken, morčací / curcan turkey. - Sync: tables a plugin makes after start-up are prepared at the next sync and their file read from the start once. - Warmers build pages as each admin account and wait while someone is using the dashboard; slow page builds are logged. - Stations: impossible sensor readings are dropped; chart ticks never fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fb3c01cdd7
commit
4193de4262
26 changed files with 704 additions and 111 deletions
|
|
@ -70,7 +70,7 @@ function food_row(array $r): array {
|
|||
|
||||
/**
|
||||
* GET /v1/food/search: q (every word a prefix of the name / brand / category), brand, country (a name or
|
||||
* ro / sk / de …), category, nutriscore ("a" or "ab"), barcode (exact, the merged duplicates' too), limit (≤ 50).
|
||||
* ro / sk / de …), category, nutriscore ("a" or "ab"), barcode (exact, the merged duplicates' too; then, 4+ digits, the ones starting with it), limit (≤ 50).
|
||||
* Ranked as the dashboard's fooddb.search: all of q in the name first, home-country products, the name
|
||||
* starting with the first word, fewer words, FTS relevance (name ≫ brand), shorter names.
|
||||
*/
|
||||
|
|
@ -78,10 +78,21 @@ function food_search(PDO $db, array $p, array $home = []): array { // $home: c
|
|||
$home = array_map(fn($c) => food_fold((string)$c), $home);
|
||||
$limit = min(50, max(1, (int)($p['limit'] ?? 20)));
|
||||
$code = preg_replace('/\D/', '', (string)($p['barcode'] ?? ''));
|
||||
if ($code !== '') {
|
||||
if ($code !== '') { // that barcode, then (4+ digits) the ones starting with it
|
||||
$st = $db->prepare('SELECT * FROM food WHERE barcode = ? UNION SELECT f.* FROM alias a JOIN food f ON f.id = a.food_id WHERE a.barcode = ?');
|
||||
$st->execute([$code, $code]);
|
||||
return array_map('food_row', $st->fetchAll());
|
||||
$rows = $st->fetchAll();
|
||||
if (strlen($code) >= 4 && count($rows) < $limit) { // a range, so the barcode index does it (':' follows '9')
|
||||
$st = $db->prepare('SELECT * FROM food WHERE barcode > ? AND barcode < ? ORDER BY barcode LIMIT ?');
|
||||
$st->execute([$code, $code . ':', $limit]);
|
||||
$ids = array_column($rows, 'id');
|
||||
foreach ($st->fetchAll() as $r) {
|
||||
if (count($rows) < $limit && !in_array($r['id'], $ids)) {
|
||||
$rows[] = $r;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array_map('food_row', $rows);
|
||||
}
|
||||
$words = food_words((string)($p['q'] ?? ''));
|
||||
$terms = array_map(fn($w) => food_term($w), $words);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue