我正在做一个游戏,需要在地图上显示POI。对于每个游戏,我都会创建10000个POI。每次创建游戏时,我的节点服务器都会创建10000个POI,并将其发布到Firebase数据库中。 (10000个数字足以说明我的问题)
我的问题是firebase'js'正在缓存所有这些对象,而我发生了内存泄漏。
如何强制Firebase破坏其缓存?我不需要在nodejs端上的这些数据,而仅在客户端上需要这些数据?
这是我用来创建它的功能。我试图简化它。
export async function addRandomPois(gameId) {
const numberOfPoiToBeGeneratedPerKM: number = 10000;
const sizeInKm = 2;
const numberOfPoiToBeGenerated = numberOfPoiToBeGeneratedPerKM * sizeInKm;
const gameData = await GameFirebaseRef.get()
const game = gameData.data();
const batches = {0: FirebaseStore.batch()};
let batchNum = 0;
for (var n = 0; n < numberOfPoiToBeGenerated; n++) {
if (n > 0 && n % 500 === 0) {
// batches cannot have more than 500 operation. So I create as much as needed
batches[batchNum]
.commit()
.then(i => delete batches[batchNum]);
batchNum++;
batches[batchNum] = FirebaseStore.batch();
}
const generatedRandomPoint = pointInCircle(game.currentCircle.center, game.nextCircle.size);
const generatedPOI = {
icon: randomIcon(),
position: generatedRandomPoint
}
const ref = firebasePOIREF.doc(guid());
batches[batchNum].set(ref, generatedPOI)
}
return batches[batchNum].commit()
.then(i => console.log(`${gameId} : randomly poi generation terminated`))
}