Some changes

This commit is contained in:
WolverinDEV
2019-07-21 15:10:06 +02:00
parent d4d6978d5f
commit d465b0a4be
2 changed files with 37 additions and 4 deletions
+26 -2
View File
@@ -297,6 +297,29 @@ bool Conversation::initialize(std::string& error) {
});
LOG_SQL_CMD(result);
/* find duplicates and remove them */
{
map<uint64_t, shared_ptr<db::MessageBlock>> blocks;
for(auto& block : this->message_blocks) {
auto& entry = blocks[block->block_offset];
if(entry) {
debugMessage(ref_server->getServerId(), "[Conversations][{}] Found duplicated block at index {}. Using newest block and dropping old one.", this->_channel_id, block->block_offset);
if(entry->begin_timestamp < block->begin_timestamp) {
entry->flag_invalid = true;
this->db_save_block(entry);
entry = block;
} else {
block->flag_invalid = true;
this->db_save_block(block);
}
} else
entry = block;
}
/* lets remove the invalid blocks */
this->message_blocks.erase(std::find_if(this->message_blocks.begin(), this->message_blocks.end(), [](const shared_ptr<db::MessageBlock>& block) { return block->flag_invalid; }), this->message_blocks.end());
}
/* lets find the last block */
if(!this->message_blocks.empty()) {
debugMessage(ref_server->getServerId(), "[Conversations][{}] Loaded {} blocks. Trying to find last block.", this->_channel_id, this->message_blocks.size());
@@ -518,8 +541,9 @@ bool Conversation::load_message_block_header(const std::shared_ptr<ts::server::c
return true;
auto block_header = make_unique<fio::BlockHeader>();
if(this->fread(&*block_header, sizeof(*block_header), block->block_offset, true) != sizeof(*block_header)) {
error = "failed to read block header";
auto read = this->fread(&*block_header, sizeof(*block_header), block->block_offset, true);
if(read != sizeof(*block_header)) {
error = "failed to read block header (read " + to_string(read) + " out of " + to_string(sizeof(*block_header)) + ": " + to_string(errno) + ")";
return false;
}
if(block_header->version != 1) {