aboutsummaryrefslogtreecommitdiff
path: root/Database.go
diff options
context:
space:
mode:
authorFChannel <=>2021-01-26 11:54:53 -0800
committerFChannel <=>2021-01-26 11:54:53 -0800
commit2868cbabf7c394c637fc8568c6981da6eb5370ca (patch)
treeef485ab567241541e23c45f581e8c0493482c3b9 /Database.go
parent4f42982f3bfa16a934fef2a6c5c6e4d153d45b4e (diff)
individual post view cache
Diffstat (limited to 'Database.go')
-rw-r--r--Database.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/Database.go b/Database.go
index cbb035b..c0df3a4 100644
--- a/Database.go
+++ b/Database.go
@@ -410,6 +410,50 @@ func GetObjectFromDB(db *sql.DB, actor Actor) Collection {
return nColl
}
+func GetObjectByIDFromDB(db *sql.DB, postID string) Collection {
+ var nColl Collection
+ var result []ObjectBase
+
+ query := `select id, name, content, type, published, updated, attributedto, attachment, preview, actor from activitystream where id=$1 and id in (select id from replies where inreplyto='') and type='Note' order by updated asc`
+
+ rows, err := db.Query(query, postID)
+
+ CheckError(err, "error query object from db")
+
+ defer rows.Close()
+ for rows.Next(){
+ var post ObjectBase
+ var actor Actor
+ var attachID string
+ var previewID string
+
+ err = rows.Scan(&post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.Updated, &post.AttributedTo, &attachID, &previewID, &actor.Id)
+
+ CheckError(err, "error scan object into post struct")
+
+ post.Actor = &actor
+
+ var postCnt int
+ var imgCnt int
+ post.Replies, postCnt, imgCnt = GetObjectRepliesDB(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.Attachment = GetObjectAttachment(db, attachID)
+
+ post.Preview = GetObjectPreview(db, previewID)
+
+ result = append(result, post)
+ }
+
+ nColl.OrderedItems = result
+
+ return nColl
+}
+
func GetInReplyToDB(db *sql.DB, parent ObjectBase) []ObjectBase {
var result []ObjectBase