mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
style: run clippy fix and fmt (#9965)
This commit is contained in:
21
.github/workflows/build-test.yml
vendored
21
.github/workflows/build-test.yml
vendored
@@ -118,6 +118,26 @@ jobs:
|
||||
- name: Run Type Check
|
||||
run: yarn typecheck
|
||||
|
||||
lint-rust:
|
||||
name: Lint Rust
|
||||
runs-on: ubuntu-latest
|
||||
needs: optimize_ci
|
||||
if: needs.optimize_ci.outputs.skip == 'false'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./.github/actions/build-rust
|
||||
with:
|
||||
no-build: 'true'
|
||||
- name: fmt check
|
||||
run: |
|
||||
rustup toolchain add nightly
|
||||
rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt
|
||||
cargo +nightly fmt --all -- --check
|
||||
- name: Clippy
|
||||
run: |
|
||||
rustup component add clippy
|
||||
cargo clippy --all-targets --all-features -- -D warnings
|
||||
|
||||
check-yarn-binary:
|
||||
name: Check yarn binary
|
||||
runs-on: ubuntu-latest
|
||||
@@ -855,6 +875,7 @@ jobs:
|
||||
needs:
|
||||
- analyze
|
||||
- lint
|
||||
- lint-rust
|
||||
- check-yarn-binary
|
||||
- e2e-test
|
||||
- e2e-legacy-blocksuite-test
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::hint::black_box;
|
||||
|
||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
|
||||
use affine_common::hashcash::Stamp;
|
||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
|
||||
fn bench_hashcash(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("hashcash");
|
||||
|
||||
@@ -129,10 +129,11 @@ impl TryFrom<&str> for Stamp {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Stamp;
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use rayon::prelude::*;
|
||||
|
||||
use super::Stamp;
|
||||
|
||||
#[test]
|
||||
fn test_mint() {
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::fs;
|
||||
|
||||
use affine_schema::get_migrator;
|
||||
use sqlx::sqlite::SqliteConnectOptions;
|
||||
use std::fs;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
|
||||
@@ -60,7 +60,8 @@ impl SqliteDocStorage {
|
||||
pub async fn list_blobs(&self) -> Result<Vec<ListedBlob>> {
|
||||
let result = sqlx::query_as!(
|
||||
ListedBlob,
|
||||
"SELECT key, size, mime, created_at FROM blobs WHERE deleted_at IS NULL ORDER BY created_at DESC;"
|
||||
"SELECT key, size, mime, created_at FROM blobs WHERE deleted_at IS NULL ORDER BY created_at \
|
||||
DESC;"
|
||||
)
|
||||
.fetch_all(&self.pool)
|
||||
.await?;
|
||||
@@ -90,7 +91,7 @@ mod tests {
|
||||
storage
|
||||
.set_blob(SetBlob {
|
||||
key: format!("test_{}", i),
|
||||
data: vec![0, 0].into(),
|
||||
data: vec![0, 0],
|
||||
mime: "text/plain".to_string(),
|
||||
})
|
||||
.await
|
||||
@@ -130,7 +131,7 @@ mod tests {
|
||||
storage
|
||||
.set_blob(SetBlob {
|
||||
key: format!("test_{}", i),
|
||||
data: vec![0, 0].into(),
|
||||
data: vec![0, 0],
|
||||
mime: "text/plain".to_string(),
|
||||
})
|
||||
.await
|
||||
@@ -178,7 +179,7 @@ mod tests {
|
||||
storage
|
||||
.set_blob(SetBlob {
|
||||
key: format!("test_{}", i),
|
||||
data: vec![0, 0].into(),
|
||||
data: vec![0, 0],
|
||||
mime: "text/plain".to_string(),
|
||||
})
|
||||
.await
|
||||
|
||||
@@ -84,7 +84,7 @@ impl SqliteDocStorage {
|
||||
}
|
||||
|
||||
// Increment timestamp by 1ms and retry
|
||||
timestamp = timestamp + chrono::Duration::milliseconds(1);
|
||||
timestamp += chrono::Duration::milliseconds(1);
|
||||
tried += 1;
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ impl SqliteDocStorage {
|
||||
let mut tx = self.pool.begin().await?;
|
||||
|
||||
sqlx::query(r#"INSERT INTO updates (doc_id, data, created_at) VALUES ($1, $2, $3);"#)
|
||||
.bind(&doc_id)
|
||||
.bind(doc_id)
|
||||
.bind(update.as_ref())
|
||||
.bind(timestamp)
|
||||
.execute(&mut *tx)
|
||||
@@ -114,7 +114,7 @@ impl SqliteDocStorage {
|
||||
ON CONFLICT(doc_id)
|
||||
DO UPDATE SET timestamp=$2;"#,
|
||||
)
|
||||
.bind(&doc_id)
|
||||
.bind(doc_id)
|
||||
.bind(timestamp)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
@@ -293,7 +293,7 @@ mod tests {
|
||||
storage
|
||||
.set_doc_snapshot(DocRecord {
|
||||
doc_id: "test".to_string(),
|
||||
bin: vec![0, 0].into(),
|
||||
bin: vec![0, 0],
|
||||
timestamp: Utc::now().naive_utc(),
|
||||
})
|
||||
.await
|
||||
@@ -373,7 +373,7 @@ mod tests {
|
||||
|
||||
let snapshot = DocRecord {
|
||||
doc_id: "test".to_string(),
|
||||
bin: vec![0, 0].into(),
|
||||
bin: vec![0, 0],
|
||||
timestamp: Utc::now().naive_utc(),
|
||||
};
|
||||
|
||||
@@ -391,7 +391,7 @@ mod tests {
|
||||
|
||||
let snapshot = DocRecord {
|
||||
doc_id: "test".to_string(),
|
||||
bin: vec![0, 0].into(),
|
||||
bin: vec![0, 0],
|
||||
timestamp: Utc::now().naive_utc(),
|
||||
};
|
||||
|
||||
@@ -404,7 +404,7 @@ mod tests {
|
||||
|
||||
let snapshot = DocRecord {
|
||||
doc_id: "test".to_string(),
|
||||
bin: vec![0, 1].into(),
|
||||
bin: vec![0, 1],
|
||||
timestamp: DateTime::from_timestamp_millis(Utc::now().timestamp_millis() - 1000)
|
||||
.unwrap()
|
||||
.naive_utc(),
|
||||
|
||||
@@ -93,7 +93,7 @@ impl DocStoragePool {
|
||||
})
|
||||
}
|
||||
|
||||
async fn get<'a>(&'a self, universal_id: String) -> Result<Ref<'a, SqliteDocStorage>> {
|
||||
async fn get(&self, universal_id: String) -> Result<Ref<SqliteDocStorage>> {
|
||||
Ok(self.pool.get(universal_id).await?)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct Ref<'a, V> {
|
||||
_guard: RwLockReadGuard<'a, V>,
|
||||
}
|
||||
|
||||
impl<'a, V> Deref for Ref<'a, V> {
|
||||
impl<V> Deref for Ref<'_, V> {
|
||||
type Target = V;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@@ -24,17 +24,17 @@ pub struct RefMut<'a, V> {
|
||||
_guard: RwLockMappedWriteGuard<'a, V>,
|
||||
}
|
||||
|
||||
impl<'a, V> Deref for RefMut<'a, V> {
|
||||
impl<V> Deref for RefMut<'_, V> {
|
||||
type Target = V;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&*self._guard
|
||||
&self._guard
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, V> DerefMut for RefMut<'a, V> {
|
||||
impl<V> DerefMut for RefMut<'_, V> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut *self._guard
|
||||
&mut self._guard
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ impl SqliteDocStoragePool {
|
||||
RefMut { _guard: lock }
|
||||
}
|
||||
|
||||
pub async fn get<'a>(&'a self, universal_id: String) -> Result<Ref<'a, SqliteDocStorage>> {
|
||||
pub async fn get(&self, universal_id: String) -> Result<Ref<SqliteDocStorage>> {
|
||||
let lock = RwLockReadGuard::try_map(self.inner.read().await, |lock| {
|
||||
if let Some(storage) = lock.get(&universal_id) {
|
||||
Some(storage)
|
||||
|
||||
@@ -51,7 +51,7 @@ impl SqliteDocStorage {
|
||||
let name: &str = row.try_get("description")?;
|
||||
Ok(name == "init_v2")
|
||||
}
|
||||
_ => return Ok(false),
|
||||
_ => Ok(false),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use sqlx::sqlite::SqliteConnectOptions;
|
||||
use std::fs;
|
||||
|
||||
use sqlx::sqlite::SqliteConnectOptions;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
napi_build::setup();
|
||||
|
||||
@@ -89,7 +89,8 @@ impl SqliteConnection {
|
||||
let blob = blob.as_ref();
|
||||
sqlx::query_as!(
|
||||
BlobRow,
|
||||
"INSERT INTO blobs (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = excluded.data",
|
||||
"INSERT INTO blobs (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = \
|
||||
excluded.data",
|
||||
key,
|
||||
blob,
|
||||
)
|
||||
@@ -288,7 +289,8 @@ impl SqliteConnection {
|
||||
pub async fn set_server_clock(&self, key: String, data: Uint8Array) -> napi::Result<()> {
|
||||
let data = data.as_ref();
|
||||
sqlx::query!(
|
||||
"INSERT INTO server_clock (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = excluded.data",
|
||||
"INSERT INTO server_clock (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = \
|
||||
excluded.data",
|
||||
key,
|
||||
data,
|
||||
)
|
||||
@@ -342,7 +344,8 @@ impl SqliteConnection {
|
||||
pub async fn set_sync_metadata(&self, key: String, data: Uint8Array) -> napi::Result<()> {
|
||||
let data = data.as_ref();
|
||||
sqlx::query!(
|
||||
"INSERT INTO sync_metadata (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = excluded.data",
|
||||
"INSERT INTO sync_metadata (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data \
|
||||
= excluded.data",
|
||||
key,
|
||||
data,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user