aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
authorFChannel <>2021-10-09 08:42:09 -0700
committerFChannel <>2022-06-19 12:52:40 -0700
commiteeffffe40cd28e3afd3f055b2114d67a99d4ba9f (patch)
tree3413595146092f94848d6cb8c804a3c3527f8a31 /database.go
parentd541ceb9d5bcdbff23324842d3a4411a9ea2bca7 (diff)
check for double replies in db
Diffstat (limited to 'database.go')
-rw-r--r--database.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/database.go b/database.go
index b0a5736..1b2df41 100644
--- a/database.go
+++ b/database.go
@@ -221,15 +221,30 @@ func WriteObjectUpdatesToDB(db *sql.DB, obj ObjectBase) {
}
func WriteObjectReplyToLocalDB(db *sql.DB, id string, replyto string) {
- query := `insert into replies (id, inreplyto) values ($1, $2)`
- _, err := db.Exec(query, id, replyto)
+ query := `select id from replies where id=$1 and inreplyto=$2`
- CheckError(err, "Could not insert local reply query")
+ rows, err := db.Query(query, id, replyto)
+
+ CheckError(err, "error selecting replies local db")
+
+ defer rows.Close()
+
+ var nID string
+ rows.Next()
+ rows.Scan(&nID)
+
+ if nID == "" {
+ query := `insert into replies (id, inreplyto) values ($1, $2)`
+
+ _, err := db.Exec(query, id, replyto)
+
+ CheckError(err, "Could not insert local reply query")
+ }
query = `select inreplyto from replies where id=$1`
- rows, err := db.Query(query, replyto)
+ rows, err = db.Query(query, replyto)
CheckError(err, "Could not query select inreplyto")