From 8976d32a2eda47013573c7e32132b19cf2949c15 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 20 Jan 2021 17:05:15 +0300 Subject: fixes #2707 (MDBX: reversed event cursors don't work at the end of table --- plugins/Dbx_mdbx/src/dbevents.cpp | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'plugins/Dbx_mdbx/src') diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp index bcbc8f6b51..7e895c7e0b 100644 --- a/plugins/Dbx_mdbx/src/dbevents.cpp +++ b/plugins/Dbx_mdbx/src/dbevents.cpp @@ -623,7 +623,7 @@ class CMdbxEventCursor : public DB::EventCursor friend class CDbxMDBX; CDbxMDBX *m_pOwner; - bool m_bForward, m_bFirst = true; + bool m_bForward; DBCachedContact *m_cc; DBEventSortingKey m_key; @@ -650,32 +650,19 @@ public: mdbx_cursor_bind(m_pOwner->StartTran(), m_pOwner->m_curEventsSort, m_pOwner->m_dbEventsSort); MDBX_val key = { &m_key, sizeof(m_key) }, data; - DBEventSortingKey dbKey; - if (m_bFirst) { - m_bFirst = false; - - if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, MDBX_SET_RANGE) != MDBX_SUCCESS) - return 0; - dbKey = *(const DBEventSortingKey *)key.iov_base; - - // we could easily move position to the next contact, if it exists - if (!m_bForward && dbKey.hContact != hContact) { - if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, MDBX_PREV) != MDBX_SUCCESS) - return 0; + switch (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, MDBX_SET)) { + case MDBX_SUCCESS: + case MDBX_NOTFOUND: + break; - dbKey = *(const DBEventSortingKey *)key.iov_base; - } + default: + return 0; } - else { - if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, MDBX_SET) != MDBX_SUCCESS) - return 0; - - if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, (m_bForward) ? MDBX_NEXT : MDBX_PREV) != MDBX_SUCCESS) - return 0; - dbKey = *(const DBEventSortingKey *)key.iov_base; - } + if (mdbx_cursor_get(m_pOwner->m_curEventsSort, &key, &data, (m_bForward) ? MDBX_NEXT : MDBX_PREV) != MDBX_SUCCESS) + return 0; + DBEventSortingKey dbKey = *(const DBEventSortingKey *)key.iov_base; if (dbKey.hContact != hContact) return 0; -- cgit v1.2.3