From 7c6cb0a463f33df4ba64ca0c8aba644526ba42bd Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sun, 17 Sep 2023 22:30:09 +0800 Subject: [PATCH] fixed sqlite3 sql migration script error and optimize following tweets order to DESC --- internal/dao/jinzhu/tweets.go | 2 +- .../sqlite3/0011_home_timeline.down.sql | 4 ++-- .../sqlite3/0011_home_timeline.up.sql | 18 +++++++++--------- scripts/paopao-sqlite3.sql | 14 +++++++------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/internal/dao/jinzhu/tweets.go b/internal/dao/jinzhu/tweets.go index b0db4b7e..c06f388d 100644 --- a/internal/dao/jinzhu/tweets.go +++ b/internal/dao/jinzhu/tweets.go @@ -489,7 +489,7 @@ func (s *tweetSrv) ListFollowingTweets(userId int64, limit, offset int) (res []* if offset >= 0 && limit > 0 { db = db.Offset(offset).Limit(limit) } - if err = db.Find(&res).Error; err != nil { + if err = db.Order("is_top DESC, latest_replied_on DESC").Find(&res).Error; err != nil { return } return diff --git a/scripts/migration/sqlite3/0011_home_timeline.down.sql b/scripts/migration/sqlite3/0011_home_timeline.down.sql index b914a617..f48b9804 100644 --- a/scripts/migration/sqlite3/0011_home_timeline.down.sql +++ b/scripts/migration/sqlite3/0011_home_timeline.down.sql @@ -2,7 +2,7 @@ DROP TABLE IF EXISTS "p_post_metric"; -- 原来的可见性: 0公开 1私密 2好友可见 3关注可见 -- 现在的可见性: 0私密 10充电可见 20订阅可见 30保留 40保留 50好友可见 60关注可见 70保留 80保留 90公开 -UPDATE p_post a +UPDATE p_post AS a SET visibility = ( SELECT CASE visibility @@ -13,7 +13,7 @@ SET visibility = ( ELSE 0 END FROM - p_post b + p_post AS b WHERE a.ID = b.ID ); diff --git a/scripts/migration/sqlite3/0011_home_timeline.up.sql b/scripts/migration/sqlite3/0011_home_timeline.up.sql index fad40a55..5aed4970 100644 --- a/scripts/migration/sqlite3/0011_home_timeline.up.sql +++ b/scripts/migration/sqlite3/0011_home_timeline.up.sql @@ -2,13 +2,13 @@ CREATE TABLE "p_post_metric" ( "id" integer NOT NULL, "post_id" integer NOT NULL, "rank_score" integer NOT NULL, - "incentive_score" integer NOT NULL, - "decay_factor" integer NOT NULL, - "motivation_factor" integer NOT NULL, - "is_del" integer NOT NULL, - "created_on" integer NOT NULL, - "modified_on" integer NOT NULL, - "deleted_on" integer NOT NULL, + "incentive_score" integer NOT NULL DEFAULT 0, + "decay_factor" integer NOT NULL DEFAULT 0, + "motivation_factor" integer NOT NULL DEFAULT 0, + "is_del" integer NOT NULL DEFAULT 0, + "created_on" integer NOT NULL DEFAULT 0, + "modified_on" integer NOT NULL DEFAULT 0, + "deleted_on" integer NOT NULL DEFAULT 0, PRIMARY KEY ("id") ); @@ -27,7 +27,7 @@ WHERE is_del=0; -- 原来的可见性: 0公开 1私密 2好友可见 3关注可见 -- 现在的可见性: 0私密 10充电可见 20订阅可见 30保留 40保留 50好友可见 60关注可见 70保留 80保留 90公开 -UPDATE p_post a +UPDATE p_post AS a SET visibility = ( SELECT CASE visibility @@ -38,7 +38,7 @@ SET visibility = ( ELSE 0 END FROM - p_post b + p_post AS b WHERE a.ID = b.ID ); diff --git a/scripts/paopao-sqlite3.sql b/scripts/paopao-sqlite3.sql index 80f334ef..0c5de46f 100644 --- a/scripts/paopao-sqlite3.sql +++ b/scripts/paopao-sqlite3.sql @@ -221,13 +221,13 @@ CREATE TABLE "p_post_metric" ( "id" integer NOT NULL, "post_id" integer NOT NULL, "rank_score" integer NOT NULL, - "incentive_score" integer NOT NULL, - "decay_factor" integer NOT NULL, - "motivation_factor" integer NOT NULL, - "is_del" integer NOT NULL, - "created_on" integer NOT NULL, - "modified_on" integer NOT NULL, - "deleted_on" integer NOT NULL, + "incentive_score" integer NOT NULL DEFAULT 0, + "decay_factor" integer NOT NULL DEFAULT 0, + "motivation_factor" integer NOT NULL DEFAULT 0, + "is_del" integer NOT NULL DEFAULT 0, + "created_on" integer NOT NULL DEFAULT 0, + "modified_on" integer NOT NULL DEFAULT 0, + "deleted_on" integer NOT NULL DEFAULT 0, PRIMARY KEY ("id") );