mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-13 22:22:10 +00:00
Merge branch 'combined_tables_2' into combined_profile
This commit is contained in:
commit
40fead2bee
|
@ -180,8 +180,7 @@ pub struct LtreeDef(pub String);
|
||||||
pub struct DbUrl(pub(crate) Box<Url>);
|
pub struct DbUrl(pub(crate) Box<Url>);
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// The report combined id
|
/// The report combined id
|
||||||
pub struct ReportCombinedId(i32);
|
pub struct ReportCombinedId(i32);
|
||||||
|
|
||||||
|
|
|
@ -6,27 +6,21 @@ use chrono::{DateTime, Utc};
|
||||||
use i_love_jesus::CursorKeysModule;
|
use i_love_jesus::CursorKeysModule;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
#[cfg(feature = "full")]
|
|
||||||
use ts_rs::TS;
|
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
|
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "full",
|
feature = "full",
|
||||||
derive(Identifiable, Queryable, Selectable, TS, CursorKeysModule)
|
derive(Identifiable, Queryable, Selectable, CursorKeysModule)
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(feature = "full", diesel(table_name = report_combined))]
|
#[cfg_attr(feature = "full", diesel(table_name = report_combined))]
|
||||||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
#[cfg_attr(feature = "full", cursor_keys_module(name = report_combined_keys))]
|
#[cfg_attr(feature = "full", cursor_keys_module(name = report_combined_keys))]
|
||||||
/// A combined reports table.
|
/// A combined reports table.
|
||||||
pub struct ReportCombined {
|
pub struct ReportCombined {
|
||||||
pub id: ReportCombinedId,
|
pub id: ReportCombinedId,
|
||||||
pub published: DateTime<Utc>,
|
pub published: DateTime<Utc>,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub post_report_id: Option<PostReportId>,
|
pub post_report_id: Option<PostReportId>,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub comment_report_id: Option<CommentReportId>,
|
pub comment_report_id: Option<CommentReportId>,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub private_message_report_id: Option<PrivateMessageReportId>,
|
pub private_message_report_id: Option<PrivateMessageReportId>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ use diesel::{
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
JoinOnDsl,
|
JoinOnDsl,
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
|
PgExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
SelectableHelper,
|
SelectableHelper,
|
||||||
};
|
};
|
||||||
|
@ -82,9 +83,12 @@ impl ReportCombinedViewInternal {
|
||||||
Some(my_person_id),
|
Some(my_person_id),
|
||||||
post::community_id,
|
post::community_id,
|
||||||
))
|
))
|
||||||
.filter(post_report::resolved.eq(false))
|
.filter(
|
||||||
.or_filter(comment_report::resolved.eq(false))
|
post_report::resolved
|
||||||
.or_filter(private_message_report::resolved.eq(false))
|
.or(comment_report::resolved)
|
||||||
|
.or(private_message_report::resolved)
|
||||||
|
.is_distinct_from(true),
|
||||||
|
)
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = community_id {
|
||||||
|
@ -191,9 +195,7 @@ impl ReportCombinedQuery {
|
||||||
.or(comment::post_id.eq(post::id)),
|
.or(comment::post_id.eq(post::id)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
// The item creator
|
// The item creator (`item_creator` is the id of this person)
|
||||||
// You can now use aliases::person1.field(person::id) / item_creator
|
|
||||||
// for all the item actions
|
|
||||||
.inner_join(
|
.inner_join(
|
||||||
aliases::person1.on(
|
aliases::person1.on(
|
||||||
post::creator_id
|
post::creator_id
|
||||||
|
@ -312,9 +314,9 @@ impl ReportCombinedQuery {
|
||||||
query = query
|
query = query
|
||||||
.filter(
|
.filter(
|
||||||
post_report::resolved
|
post_report::resolved
|
||||||
.eq(false)
|
.or(comment_report::resolved)
|
||||||
.or(comment_report::resolved.eq(false))
|
.or(private_message_report::resolved)
|
||||||
.or(private_message_report::resolved.eq(false)),
|
.is_distinct_from(true),
|
||||||
)
|
)
|
||||||
// TODO: when a `then_asc` method is added, use it here, make the id sort direction match,
|
// TODO: when a `then_asc` method is added, use it here, make the id sort direction match,
|
||||||
// and remove the separate index; unless additional columns are added to this sort
|
// and remove the separate index; unless additional columns are added to this sort
|
||||||
|
|
|
@ -7,7 +7,7 @@ CREATE TABLE report_combined (
|
||||||
comment_report_id int UNIQUE REFERENCES comment_report ON UPDATE CASCADE ON DELETE CASCADE,
|
comment_report_id int UNIQUE REFERENCES comment_report ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
private_message_report_id int UNIQUE REFERENCES private_message_report ON UPDATE CASCADE ON DELETE CASCADE,
|
private_message_report_id int UNIQUE REFERENCES private_message_report ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
-- Make sure only one of the columns is not null
|
-- Make sure only one of the columns is not null
|
||||||
CHECK ((post_report_id IS NOT NULL)::integer + (comment_report_id IS NOT NULL)::integer + (private_message_report_id IS NOT NULL)::integer = 1)
|
CHECK (num_nonnulls (post_report_id, comment_report_id, private_message_report_id) = 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_report_combined_published ON report_combined (published DESC, id DESC);
|
CREATE INDEX idx_report_combined_published ON report_combined (published DESC, id DESC);
|
||||||
|
@ -15,23 +15,27 @@ CREATE INDEX idx_report_combined_published ON report_combined (published DESC, i
|
||||||
CREATE INDEX idx_report_combined_published_asc ON report_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
CREATE INDEX idx_report_combined_published_asc ON report_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
||||||
|
|
||||||
-- Updating the history
|
-- Updating the history
|
||||||
INSERT INTO report_combined (published, post_report_id)
|
INSERT INTO report_combined (published, post_report_id, comment_report_id, private_message_report_id)
|
||||||
SELECT
|
SELECT
|
||||||
published,
|
published,
|
||||||
id
|
id,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
FROM
|
FROM
|
||||||
post_report;
|
post_report
|
||||||
|
UNION ALL
|
||||||
INSERT INTO report_combined (published, comment_report_id)
|
|
||||||
SELECT
|
SELECT
|
||||||
published,
|
published,
|
||||||
id
|
NULL,
|
||||||
|
id,
|
||||||
|
NULL
|
||||||
FROM
|
FROM
|
||||||
comment_report;
|
comment_report
|
||||||
|
UNION ALL
|
||||||
INSERT INTO report_combined (published, private_message_report_id)
|
|
||||||
SELECT
|
SELECT
|
||||||
published,
|
published,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
id
|
id
|
||||||
FROM
|
FROM
|
||||||
private_message_report;
|
private_message_report;
|
||||||
|
|
Loading…
Reference in a new issue