From 94203cdc7bc660f892d21b82f42db20db2682c11 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 15 Nov 2024 05:23:06 +0100 Subject: [PATCH] `core`: Filter meta queries on document --- acrate-core/src/meta.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/acrate-core/src/meta.rs b/acrate-core/src/meta.rs index 82da189..7ff7aa9 100644 --- a/acrate-core/src/meta.rs +++ b/acrate-core/src/meta.rs @@ -45,14 +45,16 @@ pub struct MetaProperty { impl MetaAlias { - pub async fn query_matching(conn: &mut AsyncPgConnection, subject: &str) -> QueryResult> { + pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult> { use diesel::prelude::*; use diesel_async::RunQueryDsl; use schema::meta_aliases::dsl::*; + let document_is_equal = document.eq(doc); let subject_matches_pattern = subject.into_sql::().ilike(pattern); meta_aliases + .filter(document_is_equal) .filter(subject_matches_pattern) .select(Self::as_select()) .load(conn) @@ -61,14 +63,16 @@ impl MetaAlias { } impl MetaLink { - pub async fn query_matching(conn: &mut AsyncPgConnection, subject: &str) -> QueryResult> { + pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult> { use diesel::prelude::*; use diesel_async::RunQueryDsl; use schema::meta_links::dsl::*; + let document_is_equal = document.eq(doc); let subject_matches_pattern = subject.into_sql::().ilike(pattern); meta_links + .filter(document_is_equal) .filter(subject_matches_pattern) .select(Self::as_select()) .load(conn) @@ -86,14 +90,16 @@ impl MetaLink { } impl MetaProperty { - pub async fn query_matching(conn: &mut AsyncPgConnection, subject: &str) -> QueryResult> { + pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult> { use diesel::prelude::*; use diesel_async::RunQueryDsl; use schema::meta_properties::dsl::*; + let document_is_equal = document.eq(doc); let subject_matches_pattern = subject.into_sql::().ilike(pattern); meta_properties + .filter(document_is_equal) .filter(subject_matches_pattern) .select(Self::as_select()) .load(conn)