fix: include orientation in device 304 cache check
CI / test (push) Has been cancelled

The 304 short-circuit at DeviceImageController only compared image IDs,
so flipping a device between landscape and portrait would not invalidate
the cache: the device kept showing the previously-rendered .bin even
after the user changed orientation in the webapp.

Now the device row tracks currentImageOrientation — set whenever a 200
binary response is sent — and the 304 path requires both image id AND
current orientation to match the device's stored orientation. An
orientation flip naturally falls through to the 200 path on the next
poll, the freshly-rendered portrait .bin is delivered, and the device
redraws.

No firmware change: the existing X-Current-Image-Id header from the
device is sufficient. Existing devices migrate cleanly — null
currentImageOrientation just forces one full re-send on first post-
migration poll, which is harmless.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-06 14:21:15 -04:00
parent 70d48f9b11
commit c387260ee7
4 changed files with 84 additions and 1 deletions
+11 -1
View File
@@ -69,7 +69,10 @@ class DeviceImageController extends AbstractController
}
// 304: device already has this image — skip the binary transfer and redraw.
if ($image->getId() === $currentImageId) {
// Both the image and the orientation it was last rendered at must match;
// otherwise the device's cached .bin is stale and we must re-send.
if ($image->getId() === $currentImageId
&& $device->getCurrentImageOrientation() === $device->getOrientation()) {
$this->logger->info('device.poll.no_change', [
'device_id' => $device->getId(),
'mac' => $mac,
@@ -115,10 +118,17 @@ class DeviceImageController extends AbstractController
return $r;
}
// Record the orientation we're serving the image at so the next poll's
// 304 check can detect a flip and force a re-fetch. Flushed via the
// controller's EM (markSeen() above already dirties the row).
$device->setCurrentImageOrientation($device->getOrientation());
$em->flush();
$this->logger->info('device.poll.served', [
'device_id' => $device->getId(),
'mac' => $mac,
'image_id' => $image->getId(),
'orientation' => $device->getOrientation()->value,
'interval_ms' => $intervalMs,
'bytes' => filesize($binPath),
]);