From e8cfabbfa36dd9cba293b7015a55c371edf3d1d6 Mon Sep 17 00:00:00 2001 From: FChannel <=> Date: Thu, 28 Jan 2021 21:26:55 -0800 Subject: quick fix for post and attachment count --- CacheDatabase.go | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'CacheDatabase.go') 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 } -- cgit v1.2.3