Skip to content

Commit

Permalink
fix: update updated_at
Browse files Browse the repository at this point in the history
  • Loading branch information
PoiScript committed Jul 9, 2024
1 parent aeb9c0a commit 3e36464
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 34 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vtstats-database/streams/end_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub async fn end_stream(stream_id: i32, pool: &PgPool, client: &Client) -> Resul
let now = Utc::now();

let query = sqlx::query!(
"UPDATE streams SET status = 'ended', end_time = $1 WHERE stream_id = $2",
"UPDATE streams SET status = 'ended', end_time = $1, updated_at = $1 WHERE stream_id = $2",
now,
stream_id
)
Expand All @@ -17,8 +17,9 @@ pub async fn end_stream(stream_id: i32, pool: &PgPool, client: &Client) -> Resul
if let Err(err) = super::melisearch::add_or_update(
super::melisearch::Document {
stream_id,
end_time: Some(now),
status: Some(StreamStatus::Ended),
end_time: Some(now),
updated_at: now,
..Default::default()
},
client,
Expand Down
1 change: 1 addition & 0 deletions vtstats-database/streams/melisearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Document<'q> {
pub schedule_time: Option<DateTime<Utc>>,
pub start_time: Option<DateTime<Utc>>,
pub end_time: Option<DateTime<Utc>>,
pub updated_at: DateTime<Utc>,
pub like_max: Option<i32>,
}

Expand Down
24 changes: 14 additions & 10 deletions vtstats-database/streams/start_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use chrono::{DateTime, Utc};
use meilisearch_sdk::client::Client;
use sqlx::{PgPool, Result};

use super::StreamStatus;

pub async fn start_stream(
stream_id: i32,
title: Option<&str>,
Expand All @@ -13,16 +15,14 @@ pub async fn start_stream(
let now = Utc::now();

let query = sqlx::query!(
"
UPDATE streams \
SET title = COALESCE($2, title), \
updated_at = $1, \
start_time = COALESCE(start_time, $3), \
status = 'live', \
like_max = GREATEST($4, like_max) \
WHERE stream_id = $5 \
RETURNING like_max
",
"UPDATE streams \
SET title = COALESCE($2, title), \
updated_at = $1, \
start_time = $3, \
status = 'live', \
like_max = GREATEST($4, like_max) \
WHERE stream_id = $5 \
RETURNING like_max",
now, // $1
title, // $2
start_time, // $3
Expand All @@ -37,6 +37,10 @@ RETURNING like_max
if let Err(err) = super::melisearch::add_or_update(
super::melisearch::Document {
stream_id,
title,
updated_at: now,
start_time: Some(start_time),
status: Some(StreamStatus::Live),
like_max: rec.like_max,
..Default::default()
},
Expand Down
9 changes: 7 additions & 2 deletions vtstats-database/streams/upsert_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct UpsertStreamQuery<'q> {

impl<'q> UpsertStreamQuery<'q> {
pub async fn execute(self, pool: &PgPool, client: &Client) -> Result<i32> {
let now = Utc::now();

let query = sqlx::query!(
r#"
INSERT INTO streams AS t (
Expand All @@ -36,9 +38,10 @@ INSERT INTO streams AS t (
schedule_time,
start_time,
end_time,
vtuber_id
vtuber_id,
updated_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
ON CONFLICT (platform, platform_id) DO UPDATE
SET title = COALESCE($4, t.title),
status = COALESCE($5, t.status),
Expand All @@ -58,6 +61,7 @@ ON CONFLICT (platform, platform_id) DO UPDATE
self.start_time, // $8
self.end_time, // $9
self.vtuber_id, // $10
now, // $11
)
.fetch_one(pool);

Expand All @@ -76,6 +80,7 @@ ON CONFLICT (platform, platform_id) DO UPDATE
start_time: self.start_time,
end_time: self.end_time,
vtuber_id: Some(self.vtuber_id),
updated_at: now,
..Default::default()
},
client,
Expand Down

0 comments on commit 3e36464

Please sign in to comment.