Improved threadId management
This commit is contained in:
@@ -9,14 +9,11 @@ use std::cmp::Ordering;
|
||||
use ahash::{AHashMap, AHashSet};
|
||||
use trc::AddContext;
|
||||
|
||||
use crate::{
|
||||
write::{key::DeserializeBigEndian, ValueClass},
|
||||
IndexKeyPrefix, IterateParams, Store, ValueKey, U32_LEN,
|
||||
};
|
||||
use crate::{IndexKeyPrefix, IterateParams, Store, U32_LEN, write::key::DeserializeBigEndian};
|
||||
|
||||
use super::{Comparator, ResultSet, SortedResultSet};
|
||||
|
||||
pub struct Pagination {
|
||||
pub struct Pagination<'x> {
|
||||
requested_position: i32,
|
||||
position: i32,
|
||||
pub limit: usize,
|
||||
@@ -25,7 +22,7 @@ pub struct Pagination {
|
||||
has_anchor: bool,
|
||||
anchor_found: bool,
|
||||
pub ids: Vec<u64>,
|
||||
prefix_key: Option<ValueKey<ValueClass<u32>>>,
|
||||
prefix_map: Option<&'x AHashMap<u32, u32>>,
|
||||
prefix_unique: bool,
|
||||
}
|
||||
|
||||
@@ -34,7 +31,7 @@ impl Store {
|
||||
&self,
|
||||
result_set: ResultSet,
|
||||
mut comparators: Vec<Comparator>,
|
||||
mut paginate: Pagination,
|
||||
mut paginate: Pagination<'_>,
|
||||
) -> trc::Result<SortedResultSet> {
|
||||
paginate.limit = match (result_set.results.len(), paginate.limit) {
|
||||
(0, _) => {
|
||||
@@ -105,16 +102,12 @@ impl Store {
|
||||
}
|
||||
|
||||
// Obtain prefixes
|
||||
let prefix_key = paginate.prefix_key.take();
|
||||
let prefix_map = paginate.prefix_map.take();
|
||||
let mut sorted_results = paginate.build();
|
||||
if let Some(prefix_key) = prefix_key {
|
||||
if let Some(prefix_map) = prefix_map {
|
||||
for id in sorted_results.ids.iter_mut() {
|
||||
if let Some(prefix_id) = self
|
||||
.get_value::<u32>(prefix_key.clone().with_document_id(*id as u32))
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
{
|
||||
*id |= (prefix_id as u64) << 32;
|
||||
if let Some(prefix_id) = prefix_map.get(&(*id as u32)) {
|
||||
*id |= (*prefix_id as u64) << 32;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,16 +206,12 @@ impl Store {
|
||||
});
|
||||
for (document_id, _) in sorted_ids {
|
||||
// Obtain document prefixId
|
||||
let prefix_id = if let Some(prefix_key) = &paginate.prefix_key {
|
||||
if let Some(prefix_id) = self
|
||||
.get_value(prefix_key.clone().with_document_id(document_id))
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
{
|
||||
if paginate.prefix_unique && !seen_prefixes.insert(prefix_id) {
|
||||
let prefix_id = if let Some(prefix_map) = paginate.prefix_map {
|
||||
if let Some(prefix_id) = prefix_map.get(&document_id) {
|
||||
if paginate.prefix_unique && !seen_prefixes.insert(*prefix_id) {
|
||||
continue;
|
||||
}
|
||||
prefix_id
|
||||
*prefix_id
|
||||
} else {
|
||||
// Document no longer exists?
|
||||
continue;
|
||||
@@ -242,16 +231,12 @@ impl Store {
|
||||
let mut seen_prefixes = AHashSet::new();
|
||||
for document_id in result_set.results {
|
||||
// Obtain document prefixId
|
||||
let prefix_id = if let Some(prefix_key) = &paginate.prefix_key {
|
||||
if let Some(prefix_id) = self
|
||||
.get_value(prefix_key.clone().with_document_id(document_id))
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
{
|
||||
if paginate.prefix_unique && !seen_prefixes.insert(prefix_id) {
|
||||
let prefix_id = if let Some(prefix_map) = paginate.prefix_map {
|
||||
if let Some(prefix_id) = prefix_map.get(&document_id) {
|
||||
if paginate.prefix_unique && !seen_prefixes.insert(*prefix_id) {
|
||||
continue;
|
||||
}
|
||||
prefix_id
|
||||
*prefix_id
|
||||
} else {
|
||||
// Document no longer exists?
|
||||
continue;
|
||||
@@ -270,7 +255,7 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pagination {
|
||||
impl<'x> Pagination<'x> {
|
||||
pub fn new(limit: usize, position: i32, anchor: Option<u32>, anchor_offset: i32) -> Self {
|
||||
let (has_anchor, anchor) = anchor.map(|anchor| (true, anchor)).unwrap_or((false, 0));
|
||||
|
||||
@@ -283,13 +268,13 @@ impl Pagination {
|
||||
has_anchor,
|
||||
anchor_found: false,
|
||||
ids: Vec::with_capacity(limit),
|
||||
prefix_key: None,
|
||||
prefix_map: None,
|
||||
prefix_unique: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_prefix_key(mut self, prefix_key: ValueKey<ValueClass<u32>>) -> Self {
|
||||
self.prefix_key = Some(prefix_key);
|
||||
pub fn with_prefix_map(mut self, prefix_map: &'x AHashMap<u32, u32>) -> Self {
|
||||
self.prefix_map = Some(prefix_map);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
*/
|
||||
|
||||
use std::convert::TryInto;
|
||||
use utils::{codec::leb128::Leb128_, BLOB_HASH_LEN};
|
||||
use utils::{BLOB_HASH_LEN, codec::leb128::Leb128_};
|
||||
|
||||
use crate::{
|
||||
BitmapKey, Deserialize, IndexKey, IndexKeyPrefix, Key, LogKey, ValueKey, SUBSPACE_ACL,
|
||||
BitmapKey, Deserialize, IndexKey, IndexKeyPrefix, Key, LogKey, SUBSPACE_ACL,
|
||||
SUBSPACE_BITMAP_ID, SUBSPACE_BITMAP_TAG, SUBSPACE_BITMAP_TEXT, SUBSPACE_BLOB_LINK,
|
||||
SUBSPACE_BLOB_RESERVE, SUBSPACE_COUNTER, SUBSPACE_DIRECTORY, SUBSPACE_FTS_INDEX,
|
||||
SUBSPACE_INDEXES, SUBSPACE_IN_MEMORY_COUNTER, SUBSPACE_IN_MEMORY_VALUE, SUBSPACE_LOGS,
|
||||
SUBSPACE_IN_MEMORY_COUNTER, SUBSPACE_IN_MEMORY_VALUE, SUBSPACE_INDEXES, SUBSPACE_LOGS,
|
||||
SUBSPACE_PROPERTY, SUBSPACE_QUEUE_EVENT, SUBSPACE_QUEUE_MESSAGE, SUBSPACE_QUOTA,
|
||||
SUBSPACE_REPORT_IN, SUBSPACE_REPORT_OUT, SUBSPACE_SETTINGS, SUBSPACE_TASK_QUEUE,
|
||||
SUBSPACE_TELEMETRY_INDEX, SUBSPACE_TELEMETRY_METRIC, SUBSPACE_TELEMETRY_SPAN, U32_LEN, U64_LEN,
|
||||
WITH_SUBSPACE,
|
||||
ValueKey, WITH_SUBSPACE,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
||||
Reference in New Issue
Block a user