|
@@ -1,16 +1,15 @@
|
|
|
//! Rocks DB implementation of the storage layer
|
|
|
-use crate::RocksDb;
|
|
|
+use crate::{ReferenceType, RocksDb};
|
|
|
use futures::Stream;
|
|
|
use nostr_rs_storage_base::{
|
|
|
cursor::{check_future_call, FutureResult, FutureValue},
|
|
|
Error, EventFilter, Storage,
|
|
|
};
|
|
|
use nostr_rs_types::types::Event;
|
|
|
-use rocksdb::{BoundColumnFamily, DBIteratorWithThreadMode, DB};
|
|
|
+use rocksdb::{DBIteratorWithThreadMode, DB};
|
|
|
use std::{
|
|
|
collections::VecDeque,
|
|
|
pin::Pin,
|
|
|
- sync::Arc,
|
|
|
task::{Context, Poll},
|
|
|
};
|
|
|
|
|
@@ -29,7 +28,7 @@ pub struct Cursor<'a> {
|
|
|
/// Reference to the namespace to use to query the secondary index. If none
|
|
|
/// is given the secondary_index_iterator must be constructed outside this
|
|
|
/// wrapper.
|
|
|
- index: Option<Arc<BoundColumnFamily<'a>>>,
|
|
|
+ index: Option<ReferenceType>,
|
|
|
/// The current secondary index iterator. If none is given the iterator will
|
|
|
/// try to create one using the namespace property and the first prefix from
|
|
|
/// prefixes (it will also be copied to current_prefix)
|
|
@@ -49,7 +48,7 @@ pub struct Cursor<'a> {
|
|
|
impl<'a> Cursor<'a> {
|
|
|
pub fn new(
|
|
|
db: &'a RocksDb,
|
|
|
- index: Option<Arc<BoundColumnFamily<'a>>>,
|
|
|
+ index: Option<ReferenceType>,
|
|
|
prefixes: Vec<Vec<u8>>,
|
|
|
filter: Option<EventFilter>,
|
|
|
secondary_index_iterator: Option<DBIteratorWithThreadMode<'a, DB>>,
|
|
@@ -73,10 +72,14 @@ impl<'a> Cursor<'a> {
|
|
|
fn select_next_prefix_using_secondary_index(&mut self) -> Option<()> {
|
|
|
self.index_iterator = None;
|
|
|
let prefix = self.index_keys.pop_front()?;
|
|
|
+ let index = self
|
|
|
+ .index
|
|
|
+ .map(|index| self.db.reference_to_cf_handle(index).ok())?;
|
|
|
+
|
|
|
self.index_iterator = Some(
|
|
|
self.db
|
|
|
.db
|
|
|
- .prefix_iterator_cf(self.index.as_ref()?, prefix.clone()),
|
|
|
+ .prefix_iterator_cf(index.as_ref()?, prefix.clone()),
|
|
|
);
|
|
|
self.current_index_key = prefix;
|
|
|
Some(())
|