aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <=>2021-01-28 21:26:55 -0800
committerFChannel <=>2021-01-28 21:26:55 -0800
commite8cfabbfa36dd9cba293b7015a55c371edf3d1d6 (patch)
treeb5835afc9b441e390ce7257c52d0a1ec968e44fc
parent74f5fb1e96e4c18d87ffe6838f4ab448c184ccff (diff)
quick fix for post and attachment count
-rw-r--r--CacheDatabase.go53
-rw-r--r--Database.go55
-rw-r--r--client.go24
3 files changed, 81 insertions, 51 deletions
diff --git a/CacheDatabase.go b/CacheDatabase.go
index 84a18d0..21c1a8f 100644
--- a/CacheDatabase.go
+++ b/CacheDatabase.go
@@ -4,6 +4,7 @@ import "fmt"
import "time"
import "database/sql"
import _ "github.com/lib/pq"
+import "sort"
func WriteObjectToCache(db *sql.DB, obj ObjectBase) ObjectBase {
if len(obj.Attachment) > 0 {
@@ -185,15 +186,15 @@ func GetActivityFromCache(db *sql.DB, id string) Collection {
post.Actor = &actor
- var postCnt int
- var imgCnt int
+ // var postCnt int
+ // var imgCnt int
- post.Replies, postCnt, imgCnt = GetObjectRepliesCache(db, post)
+ post.Replies, _, _ = GetObjectRepliesCache(db, post)
- post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCacheCount(db, post)
+ // post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCacheCount(db, post)
- post.Replies.TotalItems = post.Replies.TotalItems + postCnt
- post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
+ // post.Replies.TotalItems = post.Replies.TotalItems + postCnt
+ // post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
post.Attachment = GetObjectAttachmentCache(db, attachID)
@@ -230,14 +231,14 @@ func GetObjectFromCache(db *sql.DB, id string) Collection {
post.Actor = &actor
- var postCnt int
- var imgCnt int
- post.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, post)
+ // var postCnt int
+ // var imgCnt int
+ post.Replies, _, _ = GetObjectRepliesDB(db, post)
- post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCacheCount(db, post)
+ // post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCacheCount(db, post)
- post.Replies.TotalItems = post.Replies.TotalItems + postCnt
- post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
+ // post.Replies.TotalItems = post.Replies.TotalItems + postCnt
+ // post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
post.Attachment = GetObjectAttachmentCache(db, attachID)
@@ -274,14 +275,14 @@ func GetObjectByIDFromCache(db *sql.DB, postID string) Collection {
post.Actor = &actor
- var postCnt int
- var imgCnt int
- post.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, post)
+ // var postCnt int
+ // var imgCnt int
+ post.Replies, _, _ = GetObjectRepliesDB(db, post)
- post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCacheCount(db, post)
+ // post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCacheCount(db, post)
- post.Replies.TotalItems = post.Replies.TotalItems + postCnt
- post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
+ // post.Replies.TotalItems = post.Replies.TotalItems + postCnt
+ // post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
post.Attachment = GetObjectAttachmentCache(db, attachID)
@@ -402,14 +403,14 @@ func GetObjectRepliesCache(db *sql.DB, parent ObjectBase) (*CollectionBase, int,
post.Actor = &actor
- var postCnt int
- var imgCnt int
- post.Replies, postCnt, imgCnt = GetObjectRepliesRepliesCache(db, post)
+ // var postCnt int
+ // var imgCnt int
+ post.Replies, _, _ = GetObjectRepliesRepliesCache(db, post)
- post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCacheCount(db, post)
+ // post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCacheCount(db, post)
- post.Replies.TotalItems = post.Replies.TotalItems + postCnt
- post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
+ // post.Replies.TotalItems = post.Replies.TotalItems + postCnt
+ // post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
post.Attachment = GetObjectAttachmentCache(db, attachID)
@@ -467,7 +468,9 @@ func GetObjectRepliesRepliesCache(db *sql.DB, parent ObjectBase) (*CollectionBas
if len(e.Attachment) > 0 {
imgc = imgc + 1
}
- }
+ }
+
+ sort.Sort(ObjectBaseSortAsc(nColl.OrderedItems))
return &nColl, 0, 0
}
diff --git a/Database.go b/Database.go
index 19002e3..a64ceb9 100644
--- a/Database.go
+++ b/Database.go
@@ -7,6 +7,7 @@ import "time"
import "os"
import "strings"
import "regexp"
+import "sort"
func GetActorFromDB(db *sql.DB, id string) Actor {
var nActor Actor
@@ -379,14 +380,14 @@ func GetActivityFromDB(db *sql.DB, id string) Collection {
post.Actor = &actor
- var postCnt int
- var imgCnt int
- post.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, post)
+ // var postCnt int
+ // var imgCnt int
+ post.Replies, _, _ = GetObjectRepliesDB(db, post)
- post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post)
+ // post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post)
- post.Replies.TotalItems = post.Replies.TotalItems + postCnt
- post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
+ // post.Replies.TotalItems = post.Replies.TotalItems + postCnt
+ // post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
post.Attachment = GetObjectAttachment(db, attachID)
@@ -423,14 +424,14 @@ func GetObjectFromDB(db *sql.DB, id string) Collection {
post.Actor = &actor
- var postCnt int
- var imgCnt int
- post.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, post)
+ // var postCnt int
+ // var imgCnt int
+ post.Replies, _, _ = GetObjectRepliesDB(db, post)
- post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post)
+ // post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post)
- post.Replies.TotalItems = post.Replies.TotalItems + postCnt
- post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
+ // post.Replies.TotalItems = post.Replies.TotalItems + postCnt
+ // post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
post.Attachment = GetObjectAttachment(db, attachID)
@@ -467,14 +468,14 @@ func GetObjectByIDFromDB(db *sql.DB, postID string) Collection {
post.Actor = &actor
- var postCnt int
- var imgCnt int
- post.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, post)
+ // var postCnt int
+ // var imgCnt int
+ post.Replies, _, _ = GetObjectRepliesDB(db, post)
- post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post)
+ // post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post)
- post.Replies.TotalItems = post.Replies.TotalItems + postCnt
- post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
+ // post.Replies.TotalItems = post.Replies.TotalItems + postCnt
+ // post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
post.Attachment = GetObjectAttachment(db, attachID)
@@ -535,14 +536,14 @@ func GetObjectRepliesDB(db *sql.DB, parent ObjectBase) (*CollectionBase, int, in
post.Actor = &actor
- var postCnt int
- var imgCnt int
- post.Replies, postCnt, imgCnt = GetObjectRepliesRepliesDB(db, post)
+ // var postCnt int
+ // var imgCnt int
+ post.Replies, _, _ = GetObjectRepliesRepliesDB(db, post)
- post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post)
+ // post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post)
- post.Replies.TotalItems = post.Replies.TotalItems + postCnt
- post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
+ // post.Replies.TotalItems = post.Replies.TotalItems + postCnt
+ // post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt
post.Attachment = GetObjectAttachment(db, attachID)
@@ -606,7 +607,7 @@ func GetObjectRepliesReplies(db *sql.DB, parent ObjectBase) (*CollectionBase, in
var nColl CollectionBase
var result []ObjectBase
- query := `select id, name, content, type, published, attributedto, attachment, preview, actor from activitystream where id in (select id from replies where inreplyto=$1) and type='Note' order by published asc`
+ query := `select id, name, content, type, published, attributedto, attachment, preview, actor from activitystream where id in (select id from replies where inreplyto=$1) and type='Note' order by updated asc`
rows, err := db.Query(query, parent.Id)
@@ -685,7 +686,9 @@ func GetObjectRepliesRepliesDB(db *sql.DB, parent ObjectBase) (*CollectionBase,
if len(e.Attachment) > 0 {
imgc = imgc + 1
}
- }
+ }
+
+ sort.Sort(ObjectBaseSortAsc(nColl.OrderedItems))
return &nColl, 0, 0
}
diff --git a/client.go b/client.go
index 5b183c2..f0a3ed7 100644
--- a/client.go
+++ b/client.go
@@ -187,6 +187,12 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co
orderedReplies = append(orderedReplies, replies[cur])
}
}
+
+ for _, e := range returnData.Posts[i].Replies.OrderedItems {
+ if len(e.Attachment) > 0 {
+ returnData.Posts[i].Replies.TotalImgs = returnData.Posts[i].Replies.TotalImgs + 1
+ }
+ }
returnData.Posts[i].Replies.TotalItems = len(returnData.Posts[i].Replies.OrderedItems)
returnData.Posts[i].Replies.OrderedItems = orderedReplies
@@ -253,6 +259,15 @@ func CatalogGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection C
returnData.Posts = mergeCollection.OrderedItems
+ for i, _ := range returnData.Posts {
+ for _, e := range returnData.Posts[i].Replies.OrderedItems {
+ if len(e.Attachment) > 0 {
+ returnData.Posts[i].Replies.TotalImgs = returnData.Posts[i].Replies.TotalImgs + 1
+ }
+ }
+ returnData.Posts[i].Replies.TotalItems = len(returnData.Posts[i].Replies.OrderedItems)
+ }
+
t.ExecuteTemplate(w, "layout", returnData)
}
@@ -340,6 +355,15 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){
}
}
+ for i, _ := range returnData.Posts {
+ for _, e := range returnData.Posts[i].Replies.OrderedItems {
+ if len(e.Attachment) > 0 {
+ returnData.Posts[i].Replies.TotalImgs = returnData.Posts[i].Replies.TotalImgs + 1
+ }
+ }
+ returnData.Posts[i].Replies.TotalItems = len(returnData.Posts[i].Replies.OrderedItems)
+ }
+
t.ExecuteTemplate(w, "layout", returnData)
}