Changing published to saved for person_saved_combined.

This commit is contained in:
Dessalines 2025-01-02 17:08:05 -05:00
parent 918c5e820d
commit 2244fd005d
5 changed files with 9 additions and 9 deletions

View file

@ -731,12 +731,12 @@ BEGIN
AND p.thing_id = OLD.thing_id;
ELSIF (TG_OP = 'INSERT') THEN
IF NEW.saved IS NOT NULL THEN
INSERT INTO person_saved_combined (published, person_id, thing_id)
INSERT INTO person_saved_combined (saved, person_id, thing_id)
VALUES (NEW.saved, NEW.person_id, NEW.thing_id);
END IF;
ELSIF (TG_OP = 'UPDATE') THEN
IF NEW.saved IS NOT NULL THEN
INSERT INTO person_saved_combined (published, person_id, thing_id)
INSERT INTO person_saved_combined (saved, person_id, thing_id)
VALUES (NEW.saved, NEW.person_id, NEW.thing_id);
-- If saved gets set as null, delete the row
ELSE

View file

@ -751,7 +751,7 @@ diesel::table! {
diesel::table! {
person_saved_combined (id) {
id -> Int4,
published -> Timestamptz,
saved -> Timestamptz,
person_id -> Int4,
post_id -> Nullable<Int4>,
comment_id -> Nullable<Int4>,

View file

@ -16,7 +16,7 @@ use i_love_jesus::CursorKeysModule;
/// A combined person_saved table.
pub struct PersonSavedCombined {
pub id: PersonSavedCombinedId,
pub published: DateTime<Utc>,
pub saved: DateTime<Utc>,
pub person_id: PersonId,
pub post_id: Option<PostId>,
pub comment_id: Option<CommentId>,

View file

@ -220,9 +220,9 @@ impl PersonSavedCombinedQuery {
query = query.after(page_after);
}
// Sorting by published
// Sorting by saved desc
query = query
.then_desc(key::published)
.then_desc(key::saved)
// Tie breaker
.then_desc(key::id);

View file

@ -31,7 +31,7 @@ FROM
-- This one is special, because you use the saved date, not the ordinary published
CREATE TABLE person_saved_combined (
id serial PRIMARY KEY,
published timestamptz NOT NULL,
saved timestamptz NOT NULL,
person_id int NOT NULL REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE,
post_id int UNIQUE REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE,
comment_id int UNIQUE REFERENCES COMMENT ON UPDATE CASCADE ON DELETE CASCADE,
@ -39,12 +39,12 @@ CREATE TABLE person_saved_combined (
CHECK (num_nonnulls (post_id, comment_id) = 1)
);
CREATE INDEX idx_person_saved_combined_published ON person_saved_combined (published DESC, id DESC);
CREATE INDEX idx_person_saved_combined_published ON person_saved_combined (saved DESC, id DESC);
CREATE INDEX idx_person_saved_combined ON person_saved_combined (person_id);
-- Updating the history
INSERT INTO person_saved_combined (published, person_id, post_id, comment_id)
INSERT INTO person_saved_combined (saved, person_id, post_id, comment_id)
SELECT
saved,
person_id,