mirror of
https://github.com/yanislav-igonin/micrach
synced 2025-07-02 09:21:14 +03:00
feat: add threads archivation
This commit is contained in:
parent
e15aa86ad8
commit
371cfe638c
@ -140,9 +140,20 @@ func CreateThread(c *gin.Context) {
|
|||||||
c.HTML(http.StatusInternalServerError, "500.html", nil)
|
c.HTML(http.StatusInternalServerError, "500.html", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if threadsCount >= Config.App.ThreadsMaxCount {
|
if threadsCount >= Config.App.ThreadsMaxCount {
|
||||||
// получить дату последнего неархивируемого треда
|
oldestThreadUpdatedAt, err := Repositories.Posts.GetOldestThreadUpdatedAt()
|
||||||
// сделать SET для тредов старше этой даты
|
if err != nil {
|
||||||
|
log.Println("error:", err)
|
||||||
|
c.HTML(http.StatusInternalServerError, "500.html", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = Repositories.Posts.ArchiveThreadsFrom(oldestThreadUpdatedAt)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("error:", err)
|
||||||
|
c.HTML(http.StatusInternalServerError, "500.html", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := conn.Begin(context.TODO())
|
tx, err := conn.Begin(context.TODO())
|
||||||
|
@ -210,7 +210,7 @@ func (r *PostsRepository) CreateInTx(tx pgx.Tx, p Post) (int, error) {
|
|||||||
return createdPost.ID, nil
|
return createdPost.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *PostsRepository) GetOldestThreadUpdateAt() (time.Time, error) {
|
func (r *PostsRepository) GetOldestThreadUpdatedAt() (time.Time, error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT updated_at
|
SELECT updated_at
|
||||||
FROM posts
|
FROM posts
|
||||||
@ -237,10 +237,8 @@ func (r *PostsRepository) ArchiveThreadsFrom(t time.Time) error {
|
|||||||
UPDATE posts
|
UPDATE posts
|
||||||
SET is_archived = true
|
SET is_archived = true
|
||||||
WHERE
|
WHERE
|
||||||
is_parent = true
|
is_archived != true
|
||||||
AND is_deleted != true
|
AND updated_at <= $1
|
||||||
AND is_archived != true
|
|
||||||
AND updated_at > $1
|
|
||||||
`
|
`
|
||||||
|
|
||||||
_, err := Db.Pool.Exec(context.TODO(), sql, t)
|
_, err := Db.Pool.Exec(context.TODO(), sql, t)
|
||||||
|
Loading…
Reference in New Issue
Block a user