update redisMoveCanvas.js util script

This commit is contained in:
HF 2022-06-28 00:36:19 +02:00
parent 1efd40ca4e
commit d88db0ead4
3 changed files with 14 additions and 10 deletions

View File

@ -300,7 +300,7 @@
"size": 2048,
"historicalSizes": [
[
"20220626",
"20220627",
1024
]
],

View File

@ -610,7 +610,9 @@ export async function initializeTiles(
const maxBase = TILE_ZOOM_LEVEL ** zoom;
for (let cx = 0; cx < maxBase; cx += 1) {
const tileDir = `${canvasTileFolder}/${zoom}/${cx}`;
if (!fs.existsSync(tileDir)) fs.mkdirSync(tileDir);
if (!fs.existsSync(tileDir)) {
fs.mkdirSync(tileDir);
}
for (let cy = 0; cy < maxBase; cy += 1) {
const filename = `${canvasTileFolder}/${zoom}/${cx}/${cy}.webp`;
if (force || !fs.existsSync(filename)) {
@ -639,7 +641,9 @@ export async function initializeTiles(
const maxZ = TILE_ZOOM_LEVEL ** zoom;
for (let cx = 0; cx < maxZ; cx += 1) {
const tileDir = `${canvasTileFolder}/${zoom}/${cx}`;
if (!fs.existsSync(tileDir)) fs.mkdirSync(tileDir);
if (!fs.existsSync(tileDir)) {
fs.mkdirSync(tileDir);
}
for (let cy = 0; cy < maxZ; cy += 1) {
const filename = `${canvasTileFolder}/${zoom}/${cx}/${cy}.webp`;
if (force || !fs.existsSync(filename)) {

View File

@ -1,25 +1,25 @@
// this script moves chunks of a canvas, i.e. to center it after changing size
import redis from 'redis';
import { createClient } from 'redis';
//ATTENTION Make suer to set the rdis URLs right!!!
const url = "redis://localhost:6379";
const redisc = redis.createClient({ url, return_buffers: true });
const redisc = createClient({ url });
const CANVAS_SIZE = 4096;
const CANVAS_SIZE = 1024;
const TILE_SIZE = 256;
const offset = (16384 - 4096) / 2 / 256;
const offset = (2048 - 1024) / 2 / 256;
const CHUNKS_XY = CANVAS_SIZE / TILE_SIZE;
async function move() {
for (let x = CHUNKS_XY - 1; x >= 0; x--) {
for (let y = CHUNKS_XY - 1; y >= 0; y--) {
const key = `ch:1:${x}:${y}`;
const chunk = await redisc.get(key);
const key = `ch:8:${x}:${y}`;
const chunk = await redisc.get(key, { returnBuffers: true });
if (chunk) {
const buffer = new Uint8Array(chunk);
const newKey = `ch:1:${x + offset}:${y + offset}`
const newKey = `ch:8:${x + offset}:${y + offset}`
await redisc.set(newKey, Buffer.from(buffer.buffer));
await redisc.del(key);
console.log('Moved Chunk ', key, ' to ', newKey);