mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-11-26 01:13:55 +01:00
DBRedis: use HMGET in getBlocksOnZ
Big performance increase on big maps.
This commit is contained in:
parent
fabde97847
commit
9bbc4466ef
26
db-redis.cpp
26
db-redis.cpp
@ -169,22 +169,20 @@ void DBRedis::HMGET(const std::vector<BlockPos> &positions, std::vector<ustring>
|
|||||||
|
|
||||||
void DBRedis::getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos)
|
void DBRedis::getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos)
|
||||||
{
|
{
|
||||||
redisReply *reply;
|
std::vector<BlockPos> z_positions;
|
||||||
std::string tmp;
|
for (std::vector<BlockPos>::const_iterator it = posCache.begin(); it != posCache.end(); ++it) {
|
||||||
|
|
||||||
for (std::vector<BlockPos>::iterator it = posCache.begin(); it != posCache.end(); ++it) {
|
|
||||||
if (it->z != zPos) {
|
if (it->z != zPos) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tmp = i64tos(encodeBlockPos(*it));
|
z_positions.push_back(*it);
|
||||||
reply = (redisReply*) redisCommand(ctx, "HGET %s %s", hash.c_str(), tmp.c_str());
|
}
|
||||||
if(!reply)
|
std::vector<ustring> z_blocks;
|
||||||
throw std::runtime_error(std::string("redis command 'HGET %s %s' failed: ") + ctx->errstr);
|
HMGET(z_positions, &z_blocks);
|
||||||
if (reply->type == REDIS_REPLY_STRING && reply->len != 0) {
|
|
||||||
Block b(*it, ustring((const unsigned char *) reply->str, reply->len));
|
std::vector<ustring>::const_iterator z_block = z_blocks.begin();
|
||||||
blocks[b.first.x].push_back(b);
|
for (std::vector<BlockPos>::const_iterator pos = z_positions.begin();
|
||||||
} else
|
pos != z_positions.end();
|
||||||
throw std::runtime_error("Got wrong response to 'HGET %s %s' command");
|
++pos, ++z_block) {
|
||||||
freeReplyObject(reply);
|
blocks[pos->x].push_back(Block(*pos, *z_block));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user