From 2e70534967447e1c34c68d21444a81b851bd4d13 Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 31 Dec 2024 01:03:54 +0300 Subject: Storage::all_posts to return all posts for ?q=source w/o filters Change-Id: I5d1220b6a2abbcb460bdb13c088c3dbd7e4d9856 --- src/database/postgres/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/database/postgres/mod.rs') diff --git a/src/database/postgres/mod.rs b/src/database/postgres/mod.rs index 8d67bb4..1a1b98d 100644 --- a/src/database/postgres/mod.rs +++ b/src/database/postgres/mod.rs @@ -1,5 +1,6 @@ use std::borrow::Cow; +use futures::{Stream, StreamExt}; use kittybox_util::{micropub::Channel as MicropubChannel, MentionType}; use sqlx::{ConnectOptions, Executor, PgPool}; use crate::micropub::{MicropubUpdate, MicropubPropertyDeletion}; @@ -72,6 +73,16 @@ impl Storage for PostgresStorage { } + async fn all_posts<'this>(&'this self, user: &url::Url) -> Result + Send + 'this> { + let authority = user.authority().to_owned(); + Ok( + sqlx::query_scalar::<_, serde_json::Value>("SELECT mf2 FROM kittybox.mf2_json WHERE owner = $1 ORDER BY (mf2_json.mf2 #>> '{properties,published,0}') DESC") + .bind(authority) + .fetch(&self.db) + .filter_map(|f| std::future::ready(f.ok())) + ) + } + #[tracing::instrument(skip(self))] async fn categories(&self, url: &str) -> Result> { sqlx::query_scalar::<_, String>(" -- cgit 1.4.1