forked from didirus/AstralRinth
Add dependencies to search (#578)
* Add dependencies to search * add attrs for faceting * run prepare * Add user data route from token * update to 24hrs * Fix report bugs
This commit is contained in:
@@ -36,9 +36,9 @@ impl MemoryStore {
|
||||
pub fn with_capacity(capacity: usize) -> Self {
|
||||
debug!("Creating new MemoryStore");
|
||||
MemoryStore {
|
||||
inner: Arc::new(
|
||||
DashMap::<String, (usize, Duration)>::with_capacity(capacity),
|
||||
),
|
||||
inner: Arc::new(DashMap::<String, (usize, Duration)>::with_capacity(
|
||||
capacity,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,18 +74,10 @@ impl Supervised for MemoryStoreActor {
|
||||
|
||||
impl Handler<ActorMessage> for MemoryStoreActor {
|
||||
type Result = ActorResponse;
|
||||
fn handle(
|
||||
&mut self,
|
||||
msg: ActorMessage,
|
||||
ctx: &mut Self::Context,
|
||||
) -> Self::Result {
|
||||
fn handle(&mut self, msg: ActorMessage, ctx: &mut Self::Context) -> Self::Result {
|
||||
match msg {
|
||||
ActorMessage::Set { key, value, expiry } => {
|
||||
debug!(
|
||||
"Inserting key {} with expiry {}",
|
||||
&key,
|
||||
&expiry.as_secs()
|
||||
);
|
||||
debug!("Inserting key {} with expiry {}", &key, &expiry.as_secs());
|
||||
let future_key = String::from(&key);
|
||||
let now = SystemTime::now();
|
||||
let now = now.duration_since(UNIX_EPOCH).unwrap();
|
||||
@@ -93,10 +85,7 @@ impl Handler<ActorMessage> for MemoryStoreActor {
|
||||
ctx.notify_later(ActorMessage::Remove(future_key), expiry);
|
||||
ActorResponse::Set(Box::pin(future::ready(Ok(()))))
|
||||
}
|
||||
ActorMessage::Update { key, value } => match self
|
||||
.inner
|
||||
.get_mut(&key)
|
||||
{
|
||||
ActorMessage::Update { key, value } => match self.inner.get_mut(&key) {
|
||||
Some(mut c) => {
|
||||
let val_mut: &mut (usize, Duration) = c.value_mut();
|
||||
if val_mut.0 > value {
|
||||
@@ -107,22 +96,18 @@ impl Handler<ActorMessage> for MemoryStoreActor {
|
||||
let new_val = val_mut.0;
|
||||
ActorResponse::Update(Box::pin(future::ready(Ok(new_val))))
|
||||
}
|
||||
None => ActorResponse::Update(Box::pin(future::ready(Err(
|
||||
ARError::ReadWrite(
|
||||
"memory store: read failed!".to_string(),
|
||||
),
|
||||
)))),
|
||||
None => ActorResponse::Update(Box::pin(future::ready(Err(ARError::ReadWrite(
|
||||
"memory store: read failed!".to_string(),
|
||||
))))),
|
||||
},
|
||||
ActorMessage::Get(key) => {
|
||||
if self.inner.contains_key(&key) {
|
||||
let val = match self.inner.get(&key) {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
return ActorResponse::Get(Box::pin(future::ready(
|
||||
Err(ARError::ReadWrite(
|
||||
"memory store: read failed!".to_string(),
|
||||
)),
|
||||
)))
|
||||
return ActorResponse::Get(Box::pin(future::ready(Err(
|
||||
ARError::ReadWrite("memory store: read failed!".to_string()),
|
||||
))))
|
||||
}
|
||||
};
|
||||
let val = val.value().0;
|
||||
@@ -135,17 +120,14 @@ impl Handler<ActorMessage> for MemoryStoreActor {
|
||||
let c = match self.inner.get(&key) {
|
||||
Some(d) => d,
|
||||
None => {
|
||||
return ActorResponse::Expire(Box::pin(future::ready(
|
||||
Err(ARError::ReadWrite(
|
||||
"memory store: read failed!".to_string(),
|
||||
)),
|
||||
)))
|
||||
return ActorResponse::Expire(Box::pin(future::ready(Err(
|
||||
ARError::ReadWrite("memory store: read failed!".to_string()),
|
||||
))))
|
||||
}
|
||||
};
|
||||
let dur = c.value().1;
|
||||
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
||||
let res =
|
||||
dur.checked_sub(now).unwrap_or_else(|| Duration::new(0, 0));
|
||||
let res = dur.checked_sub(now).unwrap_or_else(|| Duration::new(0, 0));
|
||||
ActorResponse::Expire(Box::pin(future::ready(Ok(res))))
|
||||
}
|
||||
ActorMessage::Remove(key) => {
|
||||
@@ -153,11 +135,9 @@ impl Handler<ActorMessage> for MemoryStoreActor {
|
||||
let val = match self.inner.remove::<String>(&key) {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
return ActorResponse::Remove(Box::pin(future::ready(
|
||||
Err(ARError::ReadWrite(
|
||||
"memory store: remove failed!".to_string(),
|
||||
)),
|
||||
)))
|
||||
return ActorResponse::Remove(Box::pin(future::ready(Err(
|
||||
ARError::ReadWrite("memory store: remove failed!".to_string()),
|
||||
))))
|
||||
}
|
||||
};
|
||||
let val = val.1;
|
||||
|
||||
Reference in New Issue
Block a user