-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3983 from thematters/develop
Release: v5.0.4
- Loading branch information
Showing
40 changed files
with
723 additions
and
429 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
db/migrations/20240130120100_alter_article_and_draft_drop_fields.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
exports.up = async (knex) => { | ||
await knex.schema.table('article', (t) => { | ||
t.dropColumn('uuid') | ||
t.dropColumn('title') | ||
t.dropColumn('slug') | ||
t.dropColumn('cover') | ||
t.dropColumn('upstream_id') | ||
t.dropColumn('live') | ||
t.dropColumn('public') | ||
t.dropColumn('content') | ||
t.dropColumn('summary') | ||
t.dropColumn('language') | ||
t.dropColumn('data_hash') | ||
t.dropColumn('media_hash') | ||
t.dropColumn('iscn_id') | ||
t.dropColumn('draft_id') | ||
}) | ||
|
||
await knex.schema.table('draft', (t) => { | ||
t.dropColumn('uuid') | ||
t.dropColumn('summary_customized') | ||
t.dropColumn('word_count') | ||
t.dropColumn('language') | ||
t.dropColumn('data_hash') | ||
t.dropColumn('media_hash') | ||
t.dropColumn('prev_draft_id') | ||
t.dropColumn('iscn_id') | ||
t.dropColumn('pin_state') | ||
t.dropColumn('sensitive_by_admin') | ||
}) | ||
} | ||
|
||
exports.down = async () => { | ||
// do nothing | ||
} |
16 changes: 16 additions & 0 deletions
16
db/migrations/20240529145909_migrate_article_empty_title.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
exports.up = async (knex) => { | ||
// affect prod articles with id in (243998,262321,253780,262709,262585,262308,264186,263124,263668,265021,265465,268994,266555,267068,270498,265965,268372,267582,268126,268449,269981,269510,269294,270127,271473,270296,270958,274629,272220,273592,271769,272654,273154,273360,274074,274992,275036,275411,275909,276389,276046,276463,277421,276917,277425,277473,278627,277712,277905,278236,278033,279982,279524,279071,280941,280409,280942,281768,281276,280908,283634,282596,283018,282173,282228,282374,283452,283455,284594,284154,283836,283922,285028,389948,285432,311294,349943,359939,439395,439369,439370,420681,434821,439407,439410,439408,439415,439413,439412,439371,439414,439416,439368,439372,439375,439378,439380,439382,439383,439385,439386,439387,439388,439389,439390,439391,439392,439393,465682,439396,439397,439398,439400,439401,439405,453057,63347,469642,469640,57283,2554,29952,15420,154190,39433,39482,100932,40361,115292,122903,242266,184759,184812) | ||
await knex.raw(` | ||
UPDATE article_version SET title='未命名' | ||
WHERE id IN ( | ||
SELECT avn.id FROM article_version_newest avn | ||
JOIN article a | ||
ON avn.article_id = a.id | ||
WHERE avn.title ~ '^[[:space:]\\u00a0\\u180e\\u2007\\u200b-\\u200f\\u202f\\u2060\\ufeff\\u3000]*$' | ||
AND state='active' | ||
);`) | ||
} | ||
|
||
exports.down = async () => { | ||
// do nothing | ||
} |
110 changes: 110 additions & 0 deletions
110
db/migrations/20240612155317_update_user_reader_materialized_view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
const view = `user_reader_view` | ||
const materialized = `user_reader_materialized` | ||
|
||
exports.up = async (knex) => { | ||
await knex.raw(/*sql*/ ` | ||
drop view ${view} cascade; | ||
create view ${view} as | ||
SELECT "user".id, | ||
"user".uuid, | ||
"user".user_name, | ||
"user".display_name, | ||
"user".description, | ||
"user".avatar, | ||
"user".email, | ||
"user".email_verified, | ||
"user".mobile, | ||
"user".password_hash, | ||
"user".read_speed, | ||
"user".base_gravity, | ||
"user".curr_gravity, | ||
"user".language, | ||
"user".role, | ||
"user".state, | ||
"user".created_at, | ||
"user".updated_at, | ||
a.recent_donation, | ||
r.recent_readtime, | ||
(COALESCE(a.recent_donation, 0::bigint)+1)*COALESCE(r.recent_readtime, 0::bigint)*COALESCE(b.boost, 1::real) AS author_score | ||
FROM "user" | ||
LEFT JOIN ( SELECT ts.recipient_id, count(1) AS recent_donation | ||
FROM transaction ts | ||
JOIN article ON ts.target_id = article.id | ||
WHERE ts.created_at >= now() - interval '1 week' | ||
AND ts.state = 'succeeded' | ||
AND ts.purpose = 'donation' | ||
AND ts.currency = 'HKD' | ||
AND ts.target_type=4 | ||
AND article.state='active' | ||
GROUP BY ts.recipient_id) a ON a.recipient_id = "user".id | ||
LEFT JOIN (SELECT a2.author_id, sum(read_time) AS recent_readtime | ||
FROM article_read_count a1 | ||
JOIN article a2 ON a1.article_id = a2.id | ||
WHERE a1.created_at >= now() - interval '1 week' | ||
AND a1.user_id is not null | ||
AND a2.state = 'active' | ||
GROUP BY a2.author_id) r ON r.author_id = "user".id | ||
LEFT JOIN ( SELECT boost, | ||
user_id | ||
FROM user_boost) b ON "user".id = b.user_id | ||
where "user".state not in ('banned', 'frozen') and "user".id != 81 | ||
order by author_score desc; | ||
create materialized view ${materialized} as | ||
select * from ${view}; | ||
CREATE UNIQUE INDEX ${materialized}_id on public.${materialized} (id); | ||
CREATE INDEX ${materialized}_author_score on public.${materialized} (author_score); | ||
`) | ||
} | ||
|
||
exports.down = async (knex) => { | ||
await knex.raw(/*sql*/ ` | ||
drop view ${view} cascade; | ||
create view ${view} as | ||
SELECT "user".id, | ||
"user".uuid, | ||
"user".user_name, | ||
"user".display_name, | ||
"user".description, | ||
"user".avatar, | ||
"user".email, | ||
"user".email_verified, | ||
"user".mobile, | ||
"user".password_hash, | ||
"user".read_speed, | ||
"user".base_gravity, | ||
"user".curr_gravity, | ||
"user".language, | ||
"user".role, | ||
"user".state, | ||
"user".created_at, | ||
"user".updated_at, | ||
a.recent_donation, | ||
r.recent_readtime, | ||
(COALESCE(a.recent_donation, 0::bigint)+1)*COALESCE(r.recent_readtime, 0::bigint)*COALESCE(b.boost, 1::real) AS author_score | ||
FROM "user" | ||
LEFT JOIN ( SELECT ts.recipient_id, count(1) AS recent_donation | ||
FROM transaction ts | ||
WHERE ts.created_at >= now() - interval '1 week' AND ts.state = 'succeeded' AND ts.purpose = 'donation' AND ts.currency = 'HKD' | ||
GROUP BY ts.recipient_id) a ON a.recipient_id = "user".id | ||
LEFT JOIN (SELECT a2.author_id, sum(read_time) AS recent_readtime | ||
FROM article_read_count a1 | ||
JOIN article a2 ON a1.article_id = a2.id | ||
WHERE a1.created_at >= now() - interval '1 week' | ||
AND a1.user_id is not null | ||
GROUP BY a2.author_id) r ON r.author_id = "user".id | ||
LEFT JOIN ( SELECT boost, | ||
user_id | ||
FROM user_boost) b ON "user".id = b.user_id | ||
where "user".state not in ('banned', 'frozen') and "user".id != 81 | ||
order by author_score desc; | ||
create materialized view ${materialized} as | ||
select * from ${view}; | ||
CREATE UNIQUE INDEX ${materialized}_id on public.${materialized} (id); | ||
`) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.