From eeffffe40cd28e3afd3f055b2114d67a99d4ba9f Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sat, 9 Oct 2021 08:42:09 -0700 Subject: check for double replies in db --- database.go | 23 +++++++++++++++++++---- 1 file 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") -- cgit v1.2.3