handle chunk relevant redis requests from Event also in RedisCanvas

This commit is contained in:
HF 2020-07-01 09:18:01 +02:00
parent 19c4b23046
commit f36788c39b
2 changed files with 11 additions and 3 deletions

View File

@ -65,12 +65,12 @@ export async function clearOldEvent() {
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
`Tiny chunk in event backup, not-generated chunk at ${ic}/${jc}`, `Tiny chunk in event backup, not-generated chunk at ${ic}/${jc}`,
); );
await redis.delAsync(`ch:${CANVAS_ID}:${ic}:${jc}`); await RedisCanvas.delChunk(ic, jc, CANVAS_ID);
} else { } else {
logger.info( logger.info(
`Restoring chunk ${ic}/${jc} from event`, `Restoring chunk ${ic}/${jc} from event`,
); );
await redis.setAsync(`ch:${CANVAS_ID}:${ic}:${jc}`, chunk); await RedisCanvas.setChunk(ic, jc, chunk, CANVAS_ID);
} }
await redis.delAsync(chunkKey); await redis.delAsync(chunkKey);
} }
@ -88,7 +88,7 @@ export async function setNextEvent(minutes: number, i: number, j: number) {
await clearOldEvent(); await clearOldEvent();
for (let jc = j - 1; jc <= j + 1; jc += 1) { for (let jc = j - 1; jc <= j + 1; jc += 1) {
for (let ic = i - 1; ic <= i + 1; ic += 1) { for (let ic = i - 1; ic <= i + 1; ic += 1) {
let chunk = await redis.getAsync(`ch:${CANVAS_ID}:${ic}:${jc}`); let chunk = await RedisCanvas.getChunk(CANVAS_ID, ic, jc);
if (!chunk) { if (!chunk) {
// place a dummy Array inside to mark chunk as none-existent // place a dummy Array inside to mark chunk as none-existent
const buff = new Uint8Array(3); const buff = new Uint8Array(3);

View File

@ -57,6 +57,14 @@ class RedisCanvas {
return true; return true;
} }
static async delChunk(i: number, j: number, canvasId: number) {
const key = `ch:${canvasId}:${i}:${j}`;
await redis.delAsync(key);
chunks.delete(key);
RedisCanvas.registerChunkChange(canvasId, [i, j]);
return true;
}
static async setPixel( static async setPixel(
canvasId: number, canvasId: number,
color: number, color: number,