Merge remote-tracking branch 'upstream/main' into change-test-db

This commit is contained in:
dull b 2023-12-15 20:25:57 +00:00
commit ea6f3910eb
11 changed files with 114 additions and 98 deletions

View file

@ -85,7 +85,6 @@ steps:
- if [[ "$IGNORED" ]]; then echo "Ignored files present:\n$IGNORED\n"; exit 1; fi - if [[ "$IGNORED" ]]; then echo "Ignored files present:\n$IGNORED\n"; exit 1; fi
restore-cache: restore-cache:
group: format
image: meltwater/drone-cache:v1 image: meltwater/drone-cache:v1
pull: true pull: true
settings: settings:
@ -105,7 +104,6 @@ steps:
- ".cargo_home" - ".cargo_home"
- "target" - "target"
- "api_tests/node_modules" - "api_tests/node_modules"
exit_code: true
secrets: secrets:
[MINIO_ENDPOINT, MINIO_WRITE_USER, MINIO_WRITE_PASSWORD, MINIO_BUCKET] [MINIO_ENDPOINT, MINIO_WRITE_USER, MINIO_WRITE_PASSWORD, MINIO_BUCKET]
when: *slow_check_paths when: *slow_check_paths
@ -232,7 +230,6 @@ steps:
- ".cargo_home" - ".cargo_home"
- "target" - "target"
- "api_tests/node_modules" - "api_tests/node_modules"
exit_code: true
secrets: secrets:
[MINIO_ENDPOINT, MINIO_WRITE_USER, MINIO_WRITE_PASSWORD, MINIO_BUCKET] [MINIO_ENDPOINT, MINIO_WRITE_USER, MINIO_WRITE_PASSWORD, MINIO_BUCKET]
when: when:

24
Cargo.lock generated
View file

@ -2523,7 +2523,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "lemmy_api" name = "lemmy_api"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
@ -2551,7 +2551,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_api_common" name = "lemmy_api_common"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
@ -2585,7 +2585,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_api_crud" name = "lemmy_api_crud"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
@ -2607,7 +2607,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_apub" name = "lemmy_apub"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
@ -2646,7 +2646,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_schema" name = "lemmy_db_schema"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"async-trait", "async-trait",
@ -2682,7 +2682,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_views" name = "lemmy_db_views"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"chrono", "chrono",
@ -2701,7 +2701,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_views_actor" name = "lemmy_db_views_actor"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"diesel", "diesel",
@ -2718,7 +2718,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_db_views_moderator" name = "lemmy_db_views_moderator"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"diesel", "diesel",
"diesel-async", "diesel-async",
@ -2730,7 +2730,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_federate" name = "lemmy_federate"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"anyhow", "anyhow",
@ -2753,7 +2753,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_routes" name = "lemmy_routes"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-web", "actix-web",
@ -2777,7 +2777,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_server" name = "lemmy_server"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"actix-cors", "actix-cors",
@ -2819,7 +2819,7 @@ dependencies = [
[[package]] [[package]]
name = "lemmy_utils" name = "lemmy_utils"
version = "0.19.0-rc.16" version = "0.19.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"anyhow", "anyhow",

View file

@ -1,5 +1,5 @@
[workspace.package] [workspace.package]
version = "0.19.0-rc.16" version = "0.19.0"
edition = "2021" edition = "2021"
description = "A link aggregator for the fediverse" description = "A link aggregator for the fediverse"
license = "AGPL-3.0" license = "AGPL-3.0"
@ -84,16 +84,16 @@ unused_self = "deny"
unwrap_used = "deny" unwrap_used = "deny"
[workspace.dependencies] [workspace.dependencies]
lemmy_api = { version = "=0.19.0-rc.16", path = "./crates/api" } lemmy_api = { version = "=0.19.0", path = "./crates/api" }
lemmy_api_crud = { version = "=0.19.0-rc.16", path = "./crates/api_crud" } lemmy_api_crud = { version = "=0.19.0", path = "./crates/api_crud" }
lemmy_apub = { version = "=0.19.0-rc.16", path = "./crates/apub" } lemmy_apub = { version = "=0.19.0", path = "./crates/apub" }
lemmy_utils = { version = "=0.19.0-rc.16", path = "./crates/utils" } lemmy_utils = { version = "=0.19.0", path = "./crates/utils" }
lemmy_db_schema = { version = "=0.19.0-rc.16", path = "./crates/db_schema" } lemmy_db_schema = { version = "=0.19.0", path = "./crates/db_schema" }
lemmy_api_common = { version = "=0.19.0-rc.16", path = "./crates/api_common" } lemmy_api_common = { version = "=0.19.0", path = "./crates/api_common" }
lemmy_routes = { version = "=0.19.0-rc.16", path = "./crates/routes" } lemmy_routes = { version = "=0.19.0", path = "./crates/routes" }
lemmy_db_views = { version = "=0.19.0-rc.16", path = "./crates/db_views" } lemmy_db_views = { version = "=0.19.0", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.0-rc.16", path = "./crates/db_views_actor" } lemmy_db_views_actor = { version = "=0.19.0", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.0-rc.16", path = "./crates/db_views_moderator" } lemmy_db_views_moderator = { version = "=0.19.0", path = "./crates/db_views_moderator" }
activitypub_federation = { version = "0.5.0-beta.6", default-features = false, features = [ activitypub_federation = { version = "0.5.0-beta.6", default-features = false, features = [
"actix-web", "actix-web",
] } ] }
@ -164,7 +164,7 @@ lemmy_utils = { workspace = true }
lemmy_db_schema = { workspace = true } lemmy_db_schema = { workspace = true }
lemmy_api_common = { workspace = true } lemmy_api_common = { workspace = true }
lemmy_routes = { workspace = true } lemmy_routes = { workspace = true }
lemmy_federate = { version = "0.19.0-rc.16", path = "crates/federate" } lemmy_federate = { version = "0.19.0", path = "crates/federate" }
activitypub_federation = { workspace = true } activitypub_federation = { workspace = true }
diesel = { workspace = true } diesel = { workspace = true }
diesel-async = { workspace = true } diesel-async = { workspace = true }

View file

@ -59,52 +59,55 @@ impl Comment {
) -> Result<Comment, Error> { ) -> Result<Comment, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
// Insert, to get the id conn
let inserted_comment = insert_into(comment) .build_transaction()
.values(comment_form) .run(|conn| {
.on_conflict(ap_id) Box::pin(async move {
.do_update() // Insert, to get the id
.set(comment_form) let inserted_comment = insert_into(comment)
.get_result::<Self>(conn) .values(comment_form)
.await; .on_conflict(ap_id)
.do_update()
.set(comment_form)
.get_result::<Self>(conn)
.await?;
if let Ok(comment_insert) = inserted_comment { let comment_id = inserted_comment.id;
let comment_id = comment_insert.id;
// You need to update the ltree column // You need to update the ltree column
let ltree = Ltree(if let Some(parent_path) = parent_path { let ltree = Ltree(if let Some(parent_path) = parent_path {
// The previous parent will already have 0 in it // The previous parent will already have 0 in it
// Append this comment id // Append this comment id
format!("{}.{}", parent_path.0, comment_id) format!("{}.{}", parent_path.0, comment_id)
} else { } else {
// '0' is always the first path, append to that // '0' is always the first path, append to that
format!("{}.{}", 0, comment_id) format!("{}.{}", 0, comment_id)
}); });
let updated_comment = diesel::update(comment.find(comment_id)) let updated_comment = diesel::update(comment.find(comment_id))
.set(path.eq(ltree)) .set(path.eq(ltree))
.get_result::<Self>(conn) .get_result::<Self>(conn)
.await; .await;
// Update the child count for the parent comment_aggregates // Update the child count for the parent comment_aggregates
// You could do this with a trigger, but since you have to do this manually anyway, // You could do this with a trigger, but since you have to do this manually anyway,
// you can just have it here // you can just have it here
if let Some(parent_path) = parent_path { if let Some(parent_path) = parent_path {
// You have to update counts for all parents, not just the immediate one // You have to update counts for all parents, not just the immediate one
// TODO if the performance of this is terrible, it might be better to do this as part of a // TODO if the performance of this is terrible, it might be better to do this as part of a
// scheduled query... although the counts would often be wrong. // scheduled query... although the counts would often be wrong.
// //
// The child_count query for reference: // The child_count query for reference:
// select c.id, c.path, count(c2.id) as child_count from comment c // select c.id, c.path, count(c2.id) as child_count from comment c
// left join comment c2 on c2.path <@ c.path and c2.path != c.path // left join comment c2 on c2.path <@ c.path and c2.path != c.path
// group by c.id // group by c.id
let parent_id = parent_path.0.split('.').nth(1); let parent_id = parent_path.0.split('.').nth(1);
if let Some(parent_id) = parent_id { if let Some(parent_id) = parent_id {
let top_parent = format!("0.{}", parent_id); let top_parent = format!("0.{}", parent_id);
let update_child_count_stmt = format!( let update_child_count_stmt = format!(
" "
update comment_aggregates ca set child_count = c.child_count update comment_aggregates ca set child_count = c.child_count
from ( from (
select c.id, c.path, count(c2.id) as child_count from comment c select c.id, c.path, count(c2.id) as child_count from comment c
@ -113,15 +116,15 @@ from (
group by c.id group by c.id
) as c ) as c
where ca.comment_id = c.id" where ca.comment_id = c.id"
); );
sql_query(update_child_count_stmt).execute(conn).await?; sql_query(update_child_count_stmt).execute(conn).await?;
} }
} }
updated_comment updated_comment
} else { }) as _
inserted_comment })
} .await
} }
pub async fn read_from_apub_id( pub async fn read_from_apub_id(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,

View file

@ -13,12 +13,17 @@ use crate::{
federation_queue_state::FederationQueueState, federation_queue_state::FederationQueueState,
instance::{Instance, InstanceForm}, instance::{Instance, InstanceForm},
}, },
utils::{functions::lower, get_conn, naive_now, now, DbPool}, utils::{
functions::{coalesce, lower},
get_conn,
naive_now,
now,
DbPool,
},
}; };
use diesel::{ use diesel::{
dsl::{count_star, insert_into}, dsl::{count_star, insert_into},
result::Error, result::Error,
sql_types::{Nullable, Timestamptz},
ExpressionMethods, ExpressionMethods,
NullableExpressionMethods, NullableExpressionMethods,
QueryDsl, QueryDsl,
@ -157,5 +162,3 @@ impl Instance {
.await .await
} }
} }
sql_function! { fn coalesce(x: Nullable<Timestamptz>, y: Timestamptz) -> Timestamptz; }

View file

@ -1,4 +1,3 @@
use super::instance::coalesce;
use crate::{ use crate::{
newtypes::{CommunityId, DbUrl, PersonId, PostId}, newtypes::{CommunityId, DbUrl, PersonId, PostId},
schema::post::dsl::{ schema::post::dsl::{
@ -30,6 +29,7 @@ use crate::{
}, },
traits::{Crud, Likeable, Saveable}, traits::{Crud, Likeable, Saveable},
utils::{ utils::{
functions::coalesce,
get_conn, get_conn,
naive_now, naive_now,
DbPool, DbPool,

View file

@ -5,7 +5,14 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{LocalUserId, PersonId}, newtypes::{LocalUserId, PersonId},
schema::{local_user, person, person_aggregates}, schema::{local_user, person, person_aggregates},
utils::{functions::lower, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{
functions::{coalesce, lower},
DbConn,
DbPool,
ListFn,
Queries,
ReadFn,
},
}; };
use lemmy_utils::error::{LemmyError, LemmyErrorType}; use lemmy_utils::error::{LemmyError, LemmyErrorType};
use std::future::{ready, Ready}; use std::future::{ready, Ready};
@ -34,7 +41,9 @@ fn queries<'a>(
let mut query = local_user::table.into_boxed(); let mut query = local_user::table.into_boxed();
query = match search { query = match search {
ReadBy::Id(local_user_id) => query.filter(local_user::id.eq(local_user_id)), ReadBy::Id(local_user_id) => query.filter(local_user::id.eq(local_user_id)),
ReadBy::Email(from_email) => query.filter(local_user::email.eq(from_email)), ReadBy::Email(from_email) => {
query.filter(lower(coalesce(local_user::email, "")).eq(from_email.to_lowercase()))
}
_ => query, _ => query,
}; };
let mut query = query.inner_join(person::table); let mut query = query.inner_join(person::table);
@ -43,8 +52,8 @@ fn queries<'a>(
ReadBy::Name(name) => query.filter(lower(person::name).eq(name.to_lowercase())), ReadBy::Name(name) => query.filter(lower(person::name).eq(name.to_lowercase())),
ReadBy::NameOrEmail(name_or_email) => query.filter( ReadBy::NameOrEmail(name_or_email) => query.filter(
lower(person::name) lower(person::name)
.eq(lower(name_or_email)) .eq(lower(name_or_email.to_lowercase()))
.or(local_user::email.eq(name_or_email)), .or(lower(coalesce(local_user::email, "")).eq(name_or_email.to_lowercase())),
), ),
_ => query, _ => query,
}; };

View file

@ -4,7 +4,6 @@ use diesel::{
dsl::{exists, not, IntervalDsl}, dsl::{exists, not, IntervalDsl},
pg::Pg, pg::Pg,
result::Error, result::Error,
sql_function,
sql_types, sql_types,
BoolExpressionMethods, BoolExpressionMethods,
BoxableExpression, BoxableExpression,
@ -38,14 +37,23 @@ use lemmy_db_schema::{
post_read, post_read,
post_saved, post_saved,
}, },
utils::{fuzzy_search, get_conn, limit_and_offset, now, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{
functions::coalesce,
fuzzy_search,
get_conn,
limit_and_offset,
now,
DbConn,
DbPool,
ListFn,
Queries,
ReadFn,
},
ListingType, ListingType,
SortType, SortType,
}; };
use tracing::debug; use tracing::debug;
sql_function!(fn coalesce(x: sql_types::Nullable<sql_types::BigInt>, y: sql_types::BigInt) -> sql_types::BigInt);
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Ord { enum Ord {
Desc, Desc,
@ -482,16 +490,10 @@ fn queries<'a>() -> Queries<
query = query.filter(post_aggregates::published.gt(now() - interval)); query = query.filter(post_aggregates::published.gt(now() - interval));
} }
let tie_breaker = match options.sort.unwrap_or(SortType::Hot) {
// A second time-based sort would not be very useful
SortType::New | SortType::Old | SortType::NewComments => None,
_ => Some((Ord::Desc, field!(published))),
};
let sorts = [ let sorts = [
Some((Ord::Desc, featured_field)), Some((Ord::Desc, featured_field)),
Some(main_sort), Some(main_sort),
tie_breaker, Some((Ord::Desc, field!(post_id))),
]; ];
let sorts_iter = sorts.iter().flatten(); let sorts_iter = sorts.iter().flatten();

View file

@ -230,6 +230,7 @@ mod tests {
#[tokio::test] #[tokio::test]
#[serial] #[serial]
#[allow(clippy::dbg_macro)]
async fn exclude_deleted() { async fn exclude_deleted() {
let pool = &build_db_pool_for_tests().await; let pool = &build_db_pool_for_tests().await;
let pool = &mut pool.into(); let pool = &mut pool.into();
@ -256,6 +257,7 @@ mod tests {
.list(pool) .list(pool)
.await .await
.unwrap(); .unwrap();
dbg!(&list);
assert_eq!(list.len(), 1); assert_eq!(list.len(), 1);
assert_eq!(list[0].person.id, data.bob.id); assert_eq!(list[0].person.id, data.bob.id);

View file

@ -25,7 +25,7 @@ services:
lemmy: lemmy:
# use "image" to pull down an already compiled lemmy. make sure to comment out "build". # use "image" to pull down an already compiled lemmy. make sure to comment out "build".
# image: dessalines/lemmy:0.18.4 # image: dessalines/lemmy:0.19.0
# platform: linux/x86_64 # no arm64 support. uncomment platform if using m1. # platform: linux/x86_64 # no arm64 support. uncomment platform if using m1.
# use "build" to build your local lemmy server image for development. make sure to comment out "image". # use "build" to build your local lemmy server image for development. make sure to comment out "image".
# run: docker compose up --build # run: docker compose up --build
@ -55,7 +55,7 @@ services:
lemmy-ui: lemmy-ui:
# use "image" to pull down an already compiled lemmy-ui. make sure to comment out "build". # use "image" to pull down an already compiled lemmy-ui. make sure to comment out "build".
image: dessalines/lemmy-ui:0.19.0-rc.14 image: dessalines/lemmy-ui:0.19.0
# platform: linux/x86_64 # no arm64 support. uncomment platform if using m1. # platform: linux/x86_64 # no arm64 support. uncomment platform if using m1.
# use "build" to build your local lemmy ui image for development. make sure to comment out "image". # use "build" to build your local lemmy ui image for development. make sure to comment out "image".
# run: docker compose up --build # run: docker compose up --build

View file

@ -2,7 +2,7 @@ version: "3.7"
x-ui-default: &ui-default x-ui-default: &ui-default
init: true init: true
image: dessalines/lemmy-ui:0.19.0-rc.3 image: dessalines/lemmy-ui:0.19.0
# assuming lemmy-ui is cloned besides lemmy directory # assuming lemmy-ui is cloned besides lemmy directory
# build: # build:
# context: ../../../lemmy-ui # context: ../../../lemmy-ui