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