From 89795236377c1db1821c7ccbbc48a94562a70995 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sat, 4 Jun 2022 11:08:51 -0700 Subject: made view reported posts less gimped --- db/report.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'db') diff --git a/db/report.go b/db/report.go index 958b619..f5569fd 100644 --- a/db/report.go +++ b/db/report.go @@ -5,9 +5,14 @@ import ( "github.com/FChannel0/FChannel-Server/util" ) -type Report struct { +type Reports struct { ID string Count int + Reason []string +} + +type Report struct { + ID string Reason string } @@ -72,10 +77,10 @@ func GetLocalDelete() ([]Removed, error) { return deleted, nil } -func GetLocalReport(board string) ([]Report, error) { - var reported []Report +func GetLocalReport(board string) (map[string]Reports, error) { + var reported = make(map[string]Reports) - query := `select id, count, reason from reported where board=$1` + query := `select id, reason from reported where board=$1` rows, err := config.DB.Query(query, board) if err != nil { @@ -86,11 +91,22 @@ func GetLocalReport(board string) ([]Report, error) { for rows.Next() { var r Report - if err := rows.Scan(&r.ID, &r.Count, &r.Reason); err != nil { + if err := rows.Scan(&r.ID, &r.Reason); err != nil { return reported, util.MakeError(err, "GetLocalReportDB") } - reported = append(reported, r) + if report, has := reported[r.ID]; has { + report.Count += 1 + report.Reason = append(report.Reason, r.Reason) + reported[r.ID] = report + continue + } + + reported[r.ID] = Reports{ + ID: r.ID, + Count: 1, + Reason: []string{r.Reason}, + } } return reported, nil -- cgit v1.2.3