diff options
-rw-r--r-- | CacheDatabase.go | 12 | ||||
-rw-r--r-- | Database.go | 29 | ||||
-rw-r--r-- | Follow.go | 4 | ||||
-rw-r--r-- | OutboxPost.go | 1 | ||||
-rw-r--r-- | main.go | 1 |
5 files changed, 30 insertions, 17 deletions
diff --git a/CacheDatabase.go b/CacheDatabase.go index 992a160..9de9c78 100644 --- a/CacheDatabase.go +++ b/CacheDatabase.go @@ -20,7 +20,13 @@ func WriteObjectToCache(db *sql.DB, obj ObjectBase) ObjectBase { WriteActivitytoCache(db, obj) } - writeObjectReplyToDB(db, obj) + writeObjectReplyToDB(db, obj) + + if obj.Replies != nil { + for _, e := range obj.Replies.OrderedItems { + WriteObjectToCache(db, e) + } + } return obj } @@ -608,8 +614,8 @@ func DeleteActorCache(db *sql.DB, actorID string) { } func WriteActorToCache(db *sql.DB, actorID string) { - actor := GetActor(actorID) - collection := GetActorCollection(actor.Outbox) + actor := GetActor(actorID) + collection := GetActorCollection(actor.Outbox) for _, e := range collection.OrderedItems { WriteObjectToCache(db, e) 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) { @@ -199,11 +199,11 @@ func SetActorFollowingDB(db *sql.DB, activity Activity) Activity { if alreadyFollow { query = `delete from following where id=$1 and following=$2` activity.Summary = activity.Object.Actor.Id + " Unfollowing " + activity.Actor.Id - DeleteActorCache(db, activity.Actor.Id) + go DeleteActorCache(db, activity.Actor.Id) } else { query = `insert into following (id, following) values ($1, $2)` activity.Summary = activity.Object.Actor.Id + " Following " + activity.Actor.Id - WriteActorToCache(db, activity.Actor.Id) + go WriteActorToCache(db, activity.Actor.Id) } _, err := db.Exec(query, activity.Object.Actor.Id, activity.Actor.Id) diff --git a/OutboxPost.go b/OutboxPost.go index 12f9441..30c2cc5 100644 --- a/OutboxPost.go +++ b/OutboxPost.go @@ -406,7 +406,6 @@ func ObjectFromForm(r *http.Request, db *sql.DB, obj ObjectBase) ObjectBase { return obj } - func ParseOptions(r *http.Request, obj ObjectBase) ObjectBase { options := EscapeString(r.FormValue("options")) if options != "" { @@ -429,7 +429,6 @@ func main() { CheckError(err, "error with add board follow resp") - following := GetActorFollowingDB(db, Domain) Boards = &following |