- commit
- c84a932
- parent
- a1a0fca
- author
- Eric Bower
- date
- 2024-04-06 14:29:58 +0000 UTC
refactor(prose): discover page sorts by publish_at
3 files changed,
+4,
-17
M
db/db.go
+0,
-1
1@@ -124,7 +124,6 @@ type Post struct {
2 Hidden bool `json:"hidden"`
3 Views int `json:"views"`
4 Space string `json:"space"`
5- Score string `json:"score"`
6 Shasum string `json:"shasum"`
7 FileSize int `json:"file_size"`
8 MimeType string `json:"mime_type"`
+4,
-14
1@@ -108,8 +108,7 @@ var (
2 publish_at,
3 app_users.name as username,
4 posts.updated_at,
5- posts.mime_type,
6- 0 AS "score"
7+ posts.mime_type
8 FROM posts
9 LEFT JOIN app_users ON app_users.id = posts.user_id
10 LEFT JOIN post_tags ON post_tags.post_id = posts.id
11@@ -181,8 +180,7 @@ const (
12 publish_at,
13 app_users.name as username,
14 posts.updated_at,
15- posts.mime_type,
16- 0 AS "score"
17+ posts.mime_type
18 FROM posts
19 LEFT JOIN app_users ON app_users.id = posts.user_id
20 WHERE hidden = FALSE AND publish_at::date <= CURRENT_DATE AND cur_space = $3
21@@ -200,21 +198,14 @@ const (
22 publish_at,
23 app_users.name as username,
24 posts.updated_at,
25- posts.mime_type,
26- (
27- LOG(2.0, COALESCE(NULLIF(posts.views, 0), 1)) / (
28- EXTRACT(
29- EPOCH FROM (STATEMENT_TIMESTAMP() - posts.publish_at)
30- ) / (14 * 8600)
31- )
32- ) AS "score"
33+ posts.mime_type
34 FROM posts
35 LEFT JOIN app_users ON app_users.id = posts.user_id
36 WHERE
37 hidden = FALSE AND
38 publish_at::date <= CURRENT_DATE AND
39 cur_space = $3
40- ORDER BY score DESC
41+ ORDER BY publish_at DESC
42 LIMIT $1 OFFSET $2`
43
44 sqlSelectPopularTags = `
45@@ -772,7 +763,6 @@ func (me *PsqlDB) postPager(rs *sql.Rows, pageNum int, space string, tag string)
46 &post.Username,
47 &post.UpdatedAt,
48 &post.MimeType,
49- &post.Score,
50 )
51 if err != nil {
52 return nil, err
+0,
-2
1@@ -37,7 +37,6 @@ type PostItemData struct {
2 UpdatedAtISO string
3 UpdatedTimeAgo string
4 Padding string
5- Score string
6 }
7
8 type BlogPageData struct {
9@@ -584,7 +583,6 @@ func readHandler(w http.ResponseWriter, r *http.Request) {
10 PublishAtISO: post.PublishAt.Format(time.RFC3339),
11 UpdatedTimeAgo: shared.TimeAgo(post.UpdatedAt),
12 UpdatedAtISO: post.UpdatedAt.Format(time.RFC3339),
13- Score: post.Score,
14 }
15 data.Posts = append(data.Posts, item)
16 }