summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/storage_lmdb.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp
index 9fb2feb..58e3a9a 100644
--- a/common/storage_lmdb.cpp
+++ b/common/storage_lmdb.cpp
@@ -446,25 +446,23 @@ void DataStore::NamedDatabase::findLatest(const QByteArray &k, const std::functi
446 if ((rc = mdb_cursor_get(cursor, &key, &data, op)) == 0) { 446 if ((rc = mdb_cursor_get(cursor, &key, &data, op)) == 0) {
447 // The first lookup will find a key that is equal or greather than our key 447 // The first lookup will find a key that is equal or greather than our key
448 if (QByteArray::fromRawData((char *)key.mv_data, key.mv_size).startsWith(k)) { 448 if (QByteArray::fromRawData((char *)key.mv_data, key.mv_size).startsWith(k)) {
449 bool advanced = false; 449 //Read next value until we no longer match
450 while (QByteArray::fromRawData((char *)key.mv_data, key.mv_size).startsWith(k)) { 450 while (QByteArray::fromRawData((char *)key.mv_data, key.mv_size).startsWith(k)) {
451 advanced = true;
452 MDB_cursor_op nextOp = MDB_NEXT; 451 MDB_cursor_op nextOp = MDB_NEXT;
453 rc = mdb_cursor_get(cursor, &key, &data, nextOp); 452 rc = mdb_cursor_get(cursor, &key, &data, nextOp);
454 if (rc) { 453 if (rc) {
455 break; 454 break;
456 } 455 }
457 } 456 }
458 if (advanced) { 457 //Now read the previous value, and that's the latest one
459 MDB_cursor_op prefOp = MDB_PREV; 458 MDB_cursor_op prefOp = MDB_PREV;
460 // We read past the end above, just take the last value 459 // We read past the end above, just take the last value
461 if (rc == MDB_NOTFOUND) { 460 if (rc == MDB_NOTFOUND) {
462 prefOp = MDB_LAST; 461 prefOp = MDB_LAST;
463 }
464 rc = mdb_cursor_get(cursor, &key, &data, prefOp);
465 foundValue = true;
466 resultHandler(QByteArray::fromRawData((char *)key.mv_data, key.mv_size), QByteArray::fromRawData((char *)data.mv_data, data.mv_size));
467 } 462 }
463 rc = mdb_cursor_get(cursor, &key, &data, prefOp);
464 foundValue = true;
465 resultHandler(QByteArray::fromRawData((char *)key.mv_data, key.mv_size), QByteArray::fromRawData((char *)data.mv_data, data.mv_size));
468 } 466 }
469 } 467 }
470 468