catch invalid chunks on incremential backups

This commit is contained in:
HF 2020-06-11 01:20:36 +02:00
parent e12a9a24a7
commit ef4b4ee07e

View File

@ -111,22 +111,29 @@ export async function incrementialBackupRedis(
const curChunk = await canvasRedis.getAsync(key); const curChunk = await canvasRedis.getAsync(key);
let tileBuffer = null; let tileBuffer = null;
if (curChunk) { if (curChunk) {
// eslint-disable-next-line no-await-in-loop if (curChunk.length === TILE_SIZE * TILE_SIZE) {
const oldChunk = await backupRedis.getAsync(key); // eslint-disable-next-line no-await-in-loop
if (oldChunk) { const oldChunk = await backupRedis.getAsync(key);
let pxl = 0; if (oldChunk && oldChunk.length === TILE_SIZE * TILE_SIZE) {
while (pxl < curChunk.length) { let pxl = 0;
if (curChunk[pxl] !== oldChunk[pxl]) { while (pxl < curChunk.length) {
if (!tileBuffer) { if (curChunk[pxl] !== oldChunk[pxl]) {
tileBuffer = new Uint32Array(TILE_SIZE * TILE_SIZE); if (!tileBuffer) {
tileBuffer = new Uint32Array(TILE_SIZE * TILE_SIZE);
}
const color = palette.abgr[curChunk[pxl] & 0x3F];
tileBuffer[pxl] = color;
} }
const color = palette.abgr[curChunk[pxl] & 0x3F]; pxl += 1;
tileBuffer[pxl] = color;
} }
pxl += 1; } else {
tileBuffer = palette.buffer2ABGR(curChunk);
} }
} else { } else {
tileBuffer = palette.buffer2ABGR(curChunk); console.log(
// eslint-disable-next-line max-len
`Chunk ${x},${y} of canvas ${id} has invalid length ${curChunk.length}`,
);
} }
} }
if (tileBuffer) { if (tileBuffer) {