diff options
author | Heyang Zhou <zhy20000919@hotmail.com> | 2023-09-08 23:20:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-08 23:20:28 +0800 |
commit | 375d8a5bd50cdead2e7ede4a4a2db69b6da92876 (patch) | |
tree | e6e6cec16007e21d64367d5d89b71be9c77dfeae /ext/kv/lib.rs | |
parent | 17276a1df9fb4926f813d2b8a5ac2a2a8bf289eb (diff) |
fix(ext/kv): same `expireIn` should generate same `expireAt` (#20396)
Co-authored-by: Luca Casonato <hello@lcas.dev>
Diffstat (limited to 'ext/kv/lib.rs')
-rw-r--r-- | ext/kv/lib.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs index 294f03289..dfe00ccbf 100644 --- a/ext/kv/lib.rs +++ b/ext/kv/lib.rs @@ -12,6 +12,7 @@ use std::cell::RefCell; use std::num::NonZeroU32; use std::rc::Rc; +use chrono::Utc; use codec::decode_key; use codec::encode_key; use deno_core::anyhow::Context; @@ -383,9 +384,11 @@ impl TryFrom<V8KvCheck> for KvCheck { type V8KvMutation = (KvKey, String, Option<FromV8Value>, Option<u64>); -impl TryFrom<V8KvMutation> for KvMutation { +impl TryFrom<(V8KvMutation, u64)> for KvMutation { type Error = AnyError; - fn try_from(value: V8KvMutation) -> Result<Self, AnyError> { + fn try_from( + (value, current_timstamp): (V8KvMutation, u64), + ) -> Result<Self, AnyError> { let key = encode_v8_key(value.0)?; let kind = match (value.1.as_str(), value.2) { ("set", Some(value)) => MutationKind::Set(value.try_into()?), @@ -405,7 +408,7 @@ impl TryFrom<V8KvMutation> for KvMutation { Ok(KvMutation { key, kind, - expire_at: value.3, + expire_at: value.3.map(|expire_in| current_timstamp + expire_in), }) } } @@ -606,6 +609,7 @@ async fn op_kv_atomic_write<DBH>( where DBH: DatabaseHandler + 'static, { + let current_timestamp = Utc::now().timestamp_millis() as u64; let db = { let state = state.borrow(); let resource = @@ -631,7 +635,7 @@ where .with_context(|| "invalid check")?; let mutations = mutations .into_iter() - .map(TryInto::try_into) + .map(|mutation| TryFrom::try_from((mutation, current_timestamp))) .collect::<Result<Vec<KvMutation>, AnyError>>() .with_context(|| "invalid mutation")?; let enqueues = enqueues |