Skip to content

Commit e64b78a

Browse files
committed
chore: let's use Option<String> in index
1 parent b27fb08 commit e64b78a

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

rust/cubestore/cubestore/src/cachestore/queue_item.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ pub enum QueueItemIndexKey {
412412
ByPath(String),
413413
ByPrefixAndStatus(String, QueueItemStatus),
414414
ByPrefix(String),
415-
ByExternalId(String),
415+
ByExternalId(Option<String>),
416416
}
417417

418418
base_rocks_secondary_index!(QueueItem, QueueItemRocksIndex);
@@ -429,7 +429,7 @@ impl RocksSecondaryIndex<QueueItem, QueueItemIndexKey> for QueueItemRocksIndex {
429429
QueueItemIndexKey::ByPrefix(row.get_prefix().clone().unwrap_or("".to_string()))
430430
}
431431
QueueItemRocksIndex::ByExternalId => {
432-
QueueItemIndexKey::ByExternalId(row.get_external_id().clone().unwrap_or_default())
432+
QueueItemIndexKey::ByExternalId(row.get_external_id().clone())
433433
}
434434
}
435435
}
@@ -438,7 +438,9 @@ impl RocksSecondaryIndex<QueueItem, QueueItemIndexKey> for QueueItemRocksIndex {
438438
match key {
439439
QueueItemIndexKey::ByPath(s) => s.as_bytes().to_vec(),
440440
QueueItemIndexKey::ByPrefix(s) => s.as_bytes().to_vec(),
441-
QueueItemIndexKey::ByExternalId(s) => s.as_bytes().to_vec(),
441+
QueueItemIndexKey::ByExternalId(s) => {
442+
s.as_deref().unwrap_or("__null__").as_bytes().to_vec()
443+
}
442444
QueueItemIndexKey::ByPrefixAndStatus(prefix, s) => {
443445
let mut r = Vec::with_capacity(prefix.len() + 1);
444446
r.extend_from_slice(&prefix.as_bytes());
@@ -486,7 +488,7 @@ impl RocksSecondaryIndex<QueueItem, QueueItemIndexKey> for QueueItemRocksIndex {
486488

487489
fn should_index_row(&self, row: &QueueItem) -> bool {
488490
match self {
489-
QueueItemRocksIndex::ByExternalId => row.external_id.is_some(),
491+
Self::ByExternalId => row.external_id.is_some(),
490492
_ => true,
491493
}
492494
}

rust/cubestore/cubestore/src/cachestore/queue_result.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::cachestore::QueueKey;
1+
use crate::cachestore::queue_item::QueueItemRocksIndex;
2+
use crate::cachestore::{QueueItem, QueueKey};
23
use crate::metastore::{
34
BaseRocksTable, IdRow, IndexId, RocksEntity, RocksSecondaryIndex, RocksTable, TableId,
45
TableInfo,
@@ -111,7 +112,7 @@ rocks_table_new!(QueueResult, QueueResultRocksTable, TableId::QueueResults, {
111112
#[derive(Hash, Clone, Debug)]
112113
pub enum QueueResultIndexKey {
113114
ByPath(String),
114-
ByExternalId(String),
115+
ByExternalId(Option<String>),
115116
}
116117

117118
base_rocks_secondary_index!(QueueResult, QueueResultRocksIndex);
@@ -121,15 +122,17 @@ impl RocksSecondaryIndex<QueueResult, QueueResultIndexKey> for QueueResultRocksI
121122
match self {
122123
QueueResultRocksIndex::ByPath => QueueResultIndexKey::ByPath(row.get_path().clone()),
123124
QueueResultRocksIndex::ByExternalId => {
124-
QueueResultIndexKey::ByExternalId(row.get_external_id().clone().unwrap_or_default())
125+
QueueResultIndexKey::ByExternalId(row.get_external_id().clone())
125126
}
126127
}
127128
}
128129

129130
fn key_to_bytes(&self, key: &QueueResultIndexKey) -> Vec<u8> {
130131
match key {
131132
QueueResultIndexKey::ByPath(s) => s.as_bytes().to_vec(),
132-
QueueResultIndexKey::ByExternalId(s) => s.as_bytes().to_vec(),
133+
QueueResultIndexKey::ByExternalId(s) => {
134+
s.as_deref().unwrap_or("__null__").as_bytes().to_vec()
135+
}
133136
}
134137
}
135138

@@ -161,7 +164,7 @@ impl RocksSecondaryIndex<QueueResult, QueueResultIndexKey> for QueueResultRocksI
161164

162165
fn should_index_row(&self, row: &QueueResult) -> bool {
163166
match self {
164-
QueueResultRocksIndex::ByExternalId => row.external_id.is_some(),
167+
Self::ByExternalId => row.external_id.is_some(),
165168
_ => true,
166169
}
167170
}

0 commit comments

Comments
 (0)