From fdda0dd280c1d241e181d03602d0dcb43b93fc86 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Mon, 19 Jun 2023 13:28:07 +0200 Subject: [PATCH] Fix categories queries (#971) * more stringent hidden filter check * add missing migration case * don't do sync stuff when sync disabled * remove old stuff --- core/src/api/search.rs | 14 +++++---- core/src/library/config.rs | 1 + core/src/sync/manager.rs | 59 +++++++++++++++++++++---------------- packages/client/src/core.ts | 2 +- 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/core/src/api/search.rs b/core/src/api/search.rs index b3432390a..106af2ed4 100644 --- a/core/src/api/search.rs +++ b/core/src/api/search.rs @@ -16,7 +16,7 @@ use crate::{ use std::collections::BTreeSet; use chrono::{DateTime, FixedOffset, Utc}; -use prisma_client_rust::operator::or; +use prisma_client_rust::{operator, or}; use rspc::{alpha::AlphaRouter, ErrorCode}; use serde::{Deserialize, Serialize}; use specta::Type; @@ -110,8 +110,8 @@ impl MaybeNot { struct FilePathFilterArgs { #[specta(optional)] location_id: Option, - #[serde(default)] - search: String, + #[specta(optional)] + search: Option, #[specta(optional)] extension: Option, #[serde(default)] @@ -169,7 +169,10 @@ enum ObjectHiddenFilter { impl ObjectHiddenFilter { fn to_param(&self) -> Option { match self { - ObjectHiddenFilter::Exclude => Some(object::hidden::not(Some(true))), + ObjectHiddenFilter::Exclude => Some(or![ + object::hidden::equals(None), + object::hidden::not(Some(true)) + ]), ObjectHiddenFilter::Include => None, } } @@ -204,7 +207,7 @@ impl ObjectFilterArgs { (!self.kind.is_empty()).then(|| kind::in_vec(self.kind.into_iter().collect())), (!self.tags.is_empty()).then(|| { let tags = self.tags.into_iter().map(tag::id::equals).collect(); - let tags_on_object = tag_on_object::tag::is(vec![or(tags)]); + let tags_on_object = tag_on_object::tag::is(vec![operator::or(tags)]); tags::some(vec![tags_on_object]) }), @@ -274,6 +277,7 @@ pub fn mount() -> AlphaRouter { let params = chain_optional_iter( filter .search + .unwrap_or_default() .split(' ') .map(str::to_string) .map(name::contains), diff --git a/core/src/library/config.rs b/core/src/library/config.rs index fe9775434..6f7efb5c4 100644 --- a/core/src/library/config.rs +++ b/core/src/library/config.rs @@ -134,6 +134,7 @@ impl Migrate for LibraryConfig { config.insert("node_id".into(), Value::String(node_id.to_string())); } + 4 => {} // -_- v => unreachable!("Missing migration for library version {}", v), } diff --git a/core/src/sync/manager.rs b/core/src/sync/manager.rs index 49ceaff3f..6b0c0e40e 100644 --- a/core/src/sync/manager.rs +++ b/core/src/sync/manager.rs @@ -95,34 +95,41 @@ impl SyncManager { op: CRDTOperation, query: Q, ) -> prisma_client_rust::Result<::ReturnValue> { - let ret = match &op.typ { - CRDTOperationType::Shared(shared_op) => { - let kind = match &shared_op.data { - SharedOperationData::Create(_) => "c", - SharedOperationData::Update { .. } => "u", - SharedOperationData::Delete => "d", - }; + #[cfg(feature = "sync-messages")] + let ret = { + let ret = match &op.typ { + CRDTOperationType::Shared(shared_op) => { + let kind = match &shared_op.data { + SharedOperationData::Create(_) => "c", + SharedOperationData::Update { .. } => "u", + SharedOperationData::Delete => "d", + }; - tx._batch(( - tx.shared_operation().create( - op.id.as_bytes().to_vec(), - op.timestamp.0 as i64, - shared_op.model.to_string(), - to_vec(&shared_op.record_id).unwrap(), - kind.to_string(), - to_vec(&shared_op.data).unwrap(), - node::pub_id::equals(op.node.as_bytes().to_vec()), - vec![], - ), - query, - )) - .await? - .1 - } - _ => todo!(), + tx._batch(( + tx.shared_operation().create( + op.id.as_bytes().to_vec(), + op.timestamp.0 as i64, + shared_op.model.to_string(), + to_vec(&shared_op.record_id).unwrap(), + kind.to_string(), + to_vec(&shared_op.data).unwrap(), + node::pub_id::equals(op.node.as_bytes().to_vec()), + vec![], + ), + query, + )) + .await? + .1 + } + _ => todo!(), + }; + + self.tx.send(SyncMessage::Created(op)).ok(); + + ret }; - - self.tx.send(SyncMessage::Created(op)).ok(); + #[cfg(not(feature = "sync-messages"))] + let ret = tx._batch(vec![query]).await?.remove(0); Ok(ret) } diff --git a/packages/client/src/core.ts b/packages/client/src/core.ts index 21b2bae60..8476f1ff6 100644 --- a/packages/client/src/core.ts +++ b/packages/client/src/core.ts @@ -105,7 +105,7 @@ export type FileEraserJobInit = { location_id: number; file_path_ids: number[]; export type FilePath = { id: number; pub_id: number[]; is_dir: boolean | null; cas_id: string | null; integrity_checksum: string | null; location_id: number | null; materialized_path: string | null; name: string | null; extension: string | null; size_in_bytes: string | null; inode: number[] | null; device: number[] | null; object_id: number | null; key_id: number | null; date_created: string | null; date_modified: string | null; date_indexed: string | null } -export type FilePathFilterArgs = { locationId?: number | null; search?: string; extension?: string | null; createdAt?: OptionalRange; path?: string | null; object?: ObjectFilterArgs | null } +export type FilePathFilterArgs = { locationId?: number | null; search?: string | null; extension?: string | null; createdAt?: OptionalRange; path?: string | null; object?: ObjectFilterArgs | null } export type FilePathSearchArgs = { take?: number | null; order?: FilePathSearchOrdering | null; cursor?: number[] | null; filter?: FilePathFilterArgs }