From d0e92c69cdff5816776896ffb2628c27cc7f765f Mon Sep 17 00:00:00 2001 From: Namekuji Date: Wed, 30 Aug 2023 20:59:40 +0000 Subject: [PATCH] fix: remove native-utils from migration's dependencies --- packages/backend/native-utils/Cargo.lock | 1 + packages/backend/native-utils/migration/Cargo.toml | 5 +++-- packages/backend/native-utils/migration/src/lib.rs | 11 +++++++++++ .../src/m20230806_170616_fix_antenna_stream_ids.rs | 5 +++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/backend/native-utils/Cargo.lock b/packages/backend/native-utils/Cargo.lock index f2f3745b1c..95d3e9af23 100644 --- a/packages/backend/native-utils/Cargo.lock +++ b/packages/backend/native-utils/Cargo.lock @@ -1305,6 +1305,7 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" name = "migration" version = "0.1.0" dependencies = [ + "basen", "futures", "indicatif", "native-utils", diff --git a/packages/backend/native-utils/migration/Cargo.toml b/packages/backend/native-utils/migration/Cargo.toml index 32adb62c81..454d9bff43 100644 --- a/packages/backend/native-utils/migration/Cargo.toml +++ b/packages/backend/native-utils/migration/Cargo.toml @@ -10,11 +10,11 @@ path = "src/lib.rs" [features] default = [] -convert = ["dep:indicatif", "dep:futures"] +convert = ["dep:native-utils", "dep:indicatif", "dep:futures"] [dependencies] serde_json = "1.0.96" -native-utils = { path = "../" } +native-utils = { path = "../", optional = true } indicatif = { version = "0.17.4", features = ["tokio"], optional = true } tokio = { version = "1.28.2", features = ["full"] } futures = { version = "0.3.28", optional = true } @@ -24,6 +24,7 @@ urlencoding = "2.1.2" redis = { version = "0.23.0", features = ["tokio-rustls-comp"] } sea-orm = "0.11.3" url = { version = "2.4.0", features = ["serde"] } +basen = "0.1.0" [dependencies.sea-orm-migration] version = "0.11.0" diff --git a/packages/backend/native-utils/migration/src/lib.rs b/packages/backend/native-utils/migration/src/lib.rs index dbe2ce1a0c..57ca203f6d 100644 --- a/packages/backend/native-utils/migration/src/lib.rs +++ b/packages/backend/native-utils/migration/src/lib.rs @@ -1,5 +1,7 @@ pub use sea_orm_migration::prelude::*; +use basen::BASE36; + mod m20230531_180824_drop_reversi; mod m20230627_185451_index_note_url; mod m20230709_000510_move_antenna_to_cache; @@ -18,3 +20,12 @@ impl MigratorTrait for Migrator { ] } } + +pub fn get_timestamp(id: &str) -> i64 { + const TIME_2000: i64 = 946_684_800_000; + let n: Option = BASE36.decode_var_len(&id[0..8]); + match n { + None => -1, + Some(n) => n as i64 + TIME_2000, + } +} diff --git a/packages/backend/native-utils/migration/src/m20230806_170616_fix_antenna_stream_ids.rs b/packages/backend/native-utils/migration/src/m20230806_170616_fix_antenna_stream_ids.rs index ea23f4319f..6d45b76139 100644 --- a/packages/backend/native-utils/migration/src/m20230806_170616_fix_antenna_stream_ids.rs +++ b/packages/backend/native-utils/migration/src/m20230806_170616_fix_antenna_stream_ids.rs @@ -1,9 +1,10 @@ use std::env; -use native_utils::util::id; use redis::Commands; use sea_orm_migration::prelude::*; +use crate::get_timestamp; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -31,7 +32,7 @@ impl MigrationTrait for Migration { let all_elems: Vec>> = redis_conn.xrange_all(key).unwrap(); // Get all post IDs in stream let stream_ids = all_elems .iter() - .map(|v| format!("{}-*", id::get_timestamp(&v[1][1]))); // Get correct stream id with timestamp + .map(|v| format!("{}-*", get_timestamp(&v[1][1]))); // Get correct stream id with timestamp redis_conn.del::<_, ()>(key).unwrap(); for (j, v) in stream_ids.enumerate() { redis_conn