aboutsummaryrefslogtreecommitdiff
path: root/CacheDatabase.go
diff options
context:
space:
mode:
authorFChannel <=>2021-01-24 21:34:37 -0800
committerFChannel <=>2021-01-24 21:34:37 -0800
commita706133ba7c15f366dba66d10bf8f556147e40f1 (patch)
treeddf348539fd49f1fdd2362077959b7ab2528dd7b /CacheDatabase.go
parentb62c79a0cff349ce475d67ed23bdd5d2e0470f76 (diff)
removed cachereplies to consolidate into replies db
Diffstat (limited to 'CacheDatabase.go')
-rw-r--r--CacheDatabase.go29
1 files changed, 20 insertions, 9 deletions
diff --git a/CacheDatabase.go b/CacheDatabase.go
index 29bd4a0..035ffbb 100644
--- a/CacheDatabase.go
+++ b/CacheDatabase.go
@@ -1,6 +1,7 @@
package main
import "fmt"
+import "time"
import "database/sql"
import _ "github.com/lib/pq"
@@ -19,12 +20,22 @@ func WriteObjectToCache(db *sql.DB, obj ObjectBase) ObjectBase {
WriteActivitytoCache(db, obj)
}
- WriteObjectReplyToCache(db, obj)
- WriteObjectReplyCache(db, obj)
+ writeObjectReplyToDB(db, obj)
return obj
}
+func WriteObjectUpdatesToCache(db *sql.DB, obj ObjectBase) {
+ query := `update cacheactivitystream set updated=$1 where id=$2`
+
+ _, e := db.Exec(query, time.Now().Format(time.RFC3339), obj.Id)
+
+ if e != nil{
+ fmt.Println("error inserting updating inreplyto")
+ panic(e)
+ }
+}
+
func WriteActivitytoCache(db *sql.DB, obj ObjectBase) {
obj.Name = EscapeString(obj.Name)
@@ -194,7 +205,7 @@ func GetObjectFromCache(db *sql.DB, id string) Collection {
var nColl Collection
var result []ObjectBase
- query := `select id, name, content, type, published, updated, attributedto, attachment, preview, actor from cacheactivitystream where actor=$1 and id in (select id from cachereplies where inreplyto='') and type='Note' order by updated asc`
+ query := `select id, name, content, type, published, updated, attributedto, attachment, preview, actor from cacheactivitystream where actor=$1 and id in (select id from replies where inreplyto='') and type='Note' order by updated asc`
rows, err := db.Query(query, id)
@@ -239,7 +250,7 @@ func WriteObjectReplyToCache(db *sql.DB, obj ObjectBase) {
for i, e := range obj.InReplyTo {
if(i == 0 || IsReplyInThread(db, obj.InReplyTo[0].Id, e.Id)){
- query := `select id from cachereplies where id=$1`
+ query := `select id from replies where id=$1`
rows, err := db.Query(query, obj.Id)
@@ -320,7 +331,7 @@ func GetObjectRepliesCache(db *sql.DB, parent ObjectBase) (*CollectionBase, int,
var nColl CollectionBase
var result []ObjectBase
- query := `select id, name, content, type, published, attributedto, attachment, preview, actor from cacheactivitystream WHERE id in (select id from cachereplies where inreplyto=$1) and type='Note' order by published asc`
+ query := `select id, name, content, type, published, attributedto, attachment, preview, actor from cacheactivitystream WHERE id in (select id from replies where inreplyto=$1) and type='Note' order by published asc`
rows, err := db.Query(query, parent.Id)
@@ -380,7 +391,7 @@ func GetObjectRepliesRepliesCache(db *sql.DB, parent ObjectBase) (*CollectionBas
var nColl CollectionBase
var result []ObjectBase
- query := `select id, name, content, type, published, attributedto, attachment, preview, actor from cacheactivitystream where id in (select id from cachereplies where inreplyto=$1) and type='Note' order by published asc`
+ query := `select id, name, content, type, published, attributedto, attachment, preview, actor from cacheactivitystream where id in (select id from replies where inreplyto=$1) and type='Note' order by published asc`
rows, err := db.Query(query, parent.Id)
@@ -524,7 +535,7 @@ func DeleteObjectFromCache(db *sql.DB, id string) {
_, err = db.Exec(query, id)
CheckError(err, "could not delete object cache activitystream")
- query = `delete from cachereplies where id=$1`
+ query = `delete from replies where id=$1`
_, err = db.Exec(query, id)
CheckError(err, "could not delete cache replies activitystream")
}
@@ -532,7 +543,7 @@ func DeleteObjectFromCache(db *sql.DB, id string) {
func GetObjectPostsTotalCache(db *sql.DB, actor Actor) int{
count := 0
- query := `select count(id) from cacheactivitystream where actor=$1 and id in (select id from cachereplies where inreplyto='' and type='Note')`
+ query := `select count(id) from cacheactivitystream where actor=$1 and id in (select id from replies where inreplyto='' and type='Note')`
rows, err := db.Query(query, actor.Id)
@@ -550,7 +561,7 @@ func GetObjectPostsTotalCache(db *sql.DB, actor Actor) int{
func GetObjectImgsTotalCache(db *sql.DB, actor Actor) int{
count := 0
- query := `select count(attachment) from cacheactivitystream where actor=$1 and id in (select id from cachereplies where inreplyto='' and type='Note' )`
+ query := `select count(attachment) from cacheactivitystream where actor=$1 and id in (select id from replies where inreplyto='' and type='Note' )`
rows, err := db.Query(query, actor.Id)