aboutsummaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorFChannel <>2022-06-04 11:08:51 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit89795236377c1db1821c7ccbbc48a94562a70995 (patch)
tree75fa016c2073008d766ef9da22ca5c4405ae8bb0 /db
parentfbc0e5e5f910ea64b6b18be1a354817c195a6f04 (diff)
made view reported posts less gimped
Diffstat (limited to 'db')
-rw-r--r--db/report.go28
1 files changed, 22 insertions, 6 deletions
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