Skip to content

Commit

Permalink
chore: insert metadata after import notion zip file (#871)
Browse files Browse the repository at this point in the history
* chore: insert metadata after import notion zip file

* chore: update logs
  • Loading branch information
appflowy authored Oct 10, 2024
1 parent 8c14612 commit 14cfaa0
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 66 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ debug = true
[patch.crates-io]
# It's diffcult to resovle different version with the same crate used in AppFlowy Frontend and the Client-API crate.
# So using patch to workaround this issue.
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2934851d337c7d322c5dd7a944c05cb7ffb930d4" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2934851d337c7d322c5dd7a944c05cb7ffb930d4" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2934851d337c7d322c5dd7a944c05cb7ffb930d4" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2934851d337c7d322c5dd7a944c05cb7ffb930d4" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2934851d337c7d322c5dd7a944c05cb7ffb930d4" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2934851d337c7d322c5dd7a944c05cb7ffb930d4" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "2934851d337c7d322c5dd7a944c05cb7ffb930d4" }
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "83c85320f74de9694f4f520580261c41e8b012a1" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "83c85320f74de9694f4f520580261c41e8b012a1" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "83c85320f74de9694f4f520580261c41e8b012a1" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "83c85320f74de9694f4f520580261c41e8b012a1" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "83c85320f74de9694f4f520580261c41e8b012a1" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "83c85320f74de9694f4f520580261c41e8b012a1" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "83c85320f74de9694f4f520580261c41e8b012a1" }

[features]
history = []
Expand Down
52 changes: 49 additions & 3 deletions libs/database/src/resource_usage.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::ops::DerefMut;

use crate::pg_row::AFBlobMetadataRow;
use app_error::AppError;
use rust_decimal::prelude::ToPrimitive;
use sqlx::types::Decimal;
use sqlx::{PgPool, Transaction};
use sqlx::{Executor, PgPool, Postgres, Transaction};
use std::ops::DerefMut;

use tracing::instrument;
use uuid::Uuid;

Expand Down Expand Up @@ -63,6 +63,52 @@ pub async fn insert_blob_metadata(
Ok(())
}

#[derive(Debug, Clone)]
pub struct BulkInsertMeta {
pub object_id: String,
pub file_id: String,
pub file_type: String,
pub file_size: i64,
}

#[instrument(level = "trace", skip_all, err)]
pub async fn insert_blob_metadata_bulk<'a, E: Executor<'a, Database = Postgres>>(
executor: E,
workspace_id: &Uuid,
metadata: Vec<BulkInsertMeta>,
) -> Result<u64, sqlx::Error> {
let mut file_ids = Vec::with_capacity(metadata.len());
let mut file_types = Vec::with_capacity(metadata.len());
let mut file_sizes = Vec::with_capacity(metadata.len());

for BulkInsertMeta {
object_id,
file_id,
file_type,
file_size,
} in metadata
{
// we use BlobPathV1 to generate file_id
file_ids.push(format!("{}_{}", object_id, file_id));
file_types.push(file_type);
file_sizes.push(file_size);
}
let query = r#"
INSERT INTO af_blob_metadata (workspace_id, file_id, file_type, file_size)
SELECT $1, unnest($2::text[]), unnest($3::text[]), unnest($4::int8[])
ON CONFLICT DO NOTHING
"#;

let result = sqlx::query(query)
.bind(workspace_id)
.bind(file_ids)
.bind(file_types)
.bind(file_sizes)
.execute(executor)
.await?;

Ok(result.rows_affected())
}
#[instrument(level = "trace", skip_all, err)]
#[inline]
pub async fn delete_blob_metadata(
Expand Down
3 changes: 1 addition & 2 deletions libs/database/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,9 @@ pub async fn select_user_owned_workspaces_id<'a, E: Executor<'a, Database = Post

pub async fn update_workspace_status<'a, E: Executor<'a, Database = Postgres>>(
executor: E,
workspace_id: &str,
workspace_id: &Uuid,
is_initialized: bool,
) -> Result<(), AppError> {
let workspace_id = Uuid::parse_str(workspace_id)?;
let res = sqlx::query!(
r#"
UPDATE public.af_workspace
Expand Down
Loading

0 comments on commit 14cfaa0

Please sign in to comment.