Bläddra i källkod

Clippy issues

Cesar Rodas 3 månader sedan
förälder
incheckning
02c3cc0ab6
2 ändrade filer med 26 tillägg och 27 borttagningar
  1. 21 23
      crates/storage/rocksdb/src/cursor.rs
  2. 5 4
      crates/storage/rocksdb/src/lib.rs

+ 21 - 23
crates/storage/rocksdb/src/cursor.rs

@@ -95,32 +95,30 @@ impl<'a> Stream for Cursor<'a> {
         loop {
             let secondary_index = if let Some(iterator) = this.secondary_index_iterator.as_mut() {
                 iterator
+            } else if this.namespace.is_some() {
+                let _ = this.select_next_prefix_using_secondary_index();
+                if let Some(iterator) = this.secondary_index_iterator.as_mut() {
+                    iterator
+                } else {
+                    return Poll::Ready(None);
+                }
             } else {
-                if this.namespace.is_some() {
-                    let _ = this.select_next_prefix_using_secondary_index();
-                    if let Some(iterator) = this.secondary_index_iterator.as_mut() {
-                        iterator
-                    } else {
-                        return Poll::Ready(None);
+                // No secondary index is used to query, this means the query is
+                // using the ID filter, so it is more efficient to use the
+                // primary index to prefetch events that may satisfy the query
+                return if let Some(prefix) = this.prefixes.pop_front() {
+                    this.future_event = Some(db.get_event(prefix));
+                    match check_future_call(&mut this.future_event, &this.filter, cx) {
+                        FutureValue::Found(event) => {
+                            this.returned += 1;
+                            Poll::Ready(Some(event))
+                        }
+                        FutureValue::Pending => Poll::Pending,
+                        FutureValue::FoundNotMatch | FutureValue::Ended => continue,
                     }
                 } else {
-                    // No secondary index is used to query, this means the query is
-                    // using the ID filter, so it is more efficient to use the
-                    // primary index to prefetch events that may satisfy the query
-                    return if let Some(prefix) = this.prefixes.pop_front() {
-                        this.future_event = Some(db.get_event(prefix));
-                        match check_future_call(&mut this.future_event, &this.filter, cx) {
-                            FutureValue::Found(event) => {
-                                this.returned += 1;
-                                Poll::Ready(Some(event))
-                            }
-                            FutureValue::Pending => Poll::Pending,
-                            FutureValue::FoundNotMatch | FutureValue::Ended => continue,
-                        }
-                    } else {
-                        Poll::Ready(None)
-                    };
-                }
+                    Poll::Ready(None)
+                };
             };
 
             return match secondary_index.next() {

+ 5 - 4
crates/storage/rocksdb/src/lib.rs

@@ -204,15 +204,16 @@ impl Storage for RocksDb {
 
     async fn get_event<T: AsRef<[u8]> + Send + Sync>(&self, id: T) -> Result<Option<Event>, Error> {
         let id = id.as_ref();
-        for value in self
+        if let Some(value) = self
             .db
             .prefix_iterator_cf(&self.reference_to_cf_handle(ReferenceType::Events)?, id)
+            .next()
         {
             let (key, value) = value.map_err(|e| Error::Internal(e.to_string()))?;
-            if key.starts_with(&id) {
+
+            if key.starts_with(id) {
                 return Ok(Some(serde_json::from_slice(&value)?));
             }
-            break;
         }
 
         Ok(None)
@@ -293,7 +294,7 @@ impl Storage for RocksDb {
 
 #[cfg(test)]
 async fn new_instance(path: &str) -> RocksDb {
-    RocksDb::new(&path).expect("valid db")
+    RocksDb::new(path).expect("valid db")
 }
 
 #[cfg(test)]