found a way to avoid requesting all the MUCs history alltogether on startup

This commit is contained in:
Blue 2020-08-09 19:28:03 +03:00
parent 3a120c773a
commit ef1a9846bf
4 changed files with 34 additions and 6 deletions

View File

@ -7,6 +7,9 @@
- global availability (in drop down list) gets restored after reconnection - global availability (in drop down list) gets restored after reconnection
- status icon in active chat changes when presence of the pen pal changes - status icon in active chat changes when presence of the pen pal changes
### Improvements
- slightly reduced the traffic on the startup by not requesting history of all MUCs
## Squawk 0.1.5 (Jul 29, 2020) ## Squawk 0.1.5 (Jul 29, 2020)
### Bug fixes ### Bug fixes

View File

@ -214,6 +214,26 @@ Shared::Message Core::Archive::getElement(const QString& id) const
} }
} }
bool Core::Archive::hasElement(const QString& id) const
{
if (!opened) {
throw Closed("hasElement", jid.toStdString());
}
MDB_txn *txn;
mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
bool has;
MDB_val lmdbKey, lmdbData;
lmdbKey.mv_size = id.size();
lmdbKey.mv_data = (char*)id.toStdString().c_str();
int rc = mdb_get(txn, main, &lmdbKey, &lmdbData);
has = rc == 0;
mdb_txn_abort(txn);
return has;
}
Shared::Message Core::Archive::getMessage(const std::string& id, MDB_txn* txn) const Shared::Message Core::Archive::getMessage(const std::string& id, MDB_txn* txn) const
{ {
MDB_val lmdbKey, lmdbData; MDB_val lmdbKey, lmdbData;

View File

@ -46,6 +46,7 @@ public:
bool addElement(const Shared::Message& message); bool addElement(const Shared::Message& message);
unsigned int addElements(const std::list<Shared::Message>& messages); unsigned int addElements(const std::list<Shared::Message>& messages);
Shared::Message getElement(const QString& id) const; Shared::Message getElement(const QString& id) const;
bool hasElement(const QString& id) const;
void changeMessage(const QString& id, const QMap<QString, QVariant>& data); void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
Shared::Message oldest(); Shared::Message oldest();
QString oldestId(); QString oldestId();

View File

@ -248,18 +248,22 @@ void Core::RosterItem::appendMessageToArchive(const Shared::Message& msg)
} }
break; break;
case beginning: case beginning:
appendCache.push_back(msg); if (!archive->hasElement(msg.getId())) {
if (!syncronizing) { appendCache.push_back(msg);
requestHistory(-1, getId(msg)); if (!syncronizing) {
requestHistory(-1, getId(msg));
}
} }
break; break;
case end: case end:
archive->addElement(msg); archive->addElement(msg);
break; break;
case chunk: case chunk:
appendCache.push_back(msg); if (!archive->hasElement(msg.getId())) {
if (!syncronizing) { appendCache.push_back(msg);
requestHistory(-1, getId(msg)); if (!syncronizing) {
requestHistory(-1, getId(msg));
}
} }
break; break;
case complete: case complete: