From 3b923a6f098cacf35f309e44a4c67a6a576fba4e Mon Sep 17 00:00:00 2001 From: FChannel <=> Date: Mon, 25 Jan 2021 11:02:42 -0800 Subject: follow cache sync --- Database.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'Database.go') diff --git a/Database.go b/Database.go index cdf23e7..313ffd8 100644 --- a/Database.go +++ b/Database.go @@ -214,16 +214,14 @@ func WriteObjectReplyToLocalDB(db *sql.DB, id string, replyto string) { } func writeObjectReplyToDB(db *sql.DB, obj ObjectBase) { - for i, e := range obj.InReplyTo { - if(i == 0 || IsReplyInThread(db, obj.InReplyTo[0].Id, e.Id)){ - query := `insert into replies (id, inreplyto) values ($1, $2)` - - _, err := db.Exec(query, obj.Id, e.Id) - - if err != nil{ - fmt.Println("error inserting replies") - panic(err) - } + for _, e := range obj.InReplyTo { + query := `insert into replies (id, inreplyto) values ($1, $2)` + + _, err := db.Exec(query, obj.Id, e.Id) + + if err != nil{ + fmt.Println("error inserting replies") + panic(err) } update := true @@ -242,6 +240,17 @@ func writeObjectReplyToDB(db *sql.DB, obj ObjectBase) { } } } + + if len(obj.InReplyTo) < 1 { + query := `insert into replies (id, inreplyto) values ($1, $2)` + + _, err := db.Exec(query, obj.Id, "") + + if err != nil{ + fmt.Println("error inserting replies cache") + panic(err) + } + } } func WriteWalletToDB(db *sql.DB, obj ObjectBase) { -- cgit v1.2.3