diff options
author | FChannel <=> | 2021-01-28 21:26:55 -0800 |
---|---|---|
committer | FChannel <=> | 2021-01-28 21:26:55 -0800 |
commit | e8cfabbfa36dd9cba293b7015a55c371edf3d1d6 (patch) | |
tree | b5835afc9b441e390ce7257c52d0a1ec968e44fc /CacheDatabase.go | |
parent | 74f5fb1e96e4c18d87ffe6838f4ab448c184ccff (diff) |
quick fix for post and attachment count
Diffstat (limited to 'CacheDatabase.go')
-rw-r--r-- | CacheDatabase.go | 53 |
1 files changed, 28 insertions, 25 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 } |