aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
authorFChannel <>2021-07-30 16:28:55 -0700
committerFChannel <>2021-07-30 16:28:55 -0700
commita1ecad89f575b7d8542eea75979b4c11bfa199d4 (patch)
tree6e06ae5cbd75cc527167a4033e5faa48b0f7939f /database.go
parent7c6ee8f4073a5b8fd9cc065f225c9f09f21ee4a1 (diff)
added removal of inactive instances from following/followers after 24hrs
Diffstat (limited to 'database.go')
-rw-r--r--database.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/database.go b/database.go
index 911a42d..f0601ce 100644
--- a/database.go
+++ b/database.go
@@ -1729,3 +1729,55 @@ func SetActorAutoSubscribeDB(db *sql.DB, id string) {
CheckError(err, "error with set actor auto subscribe status from db")
}
+
+func AddInstanceToInactiveDB(db *sql.DB, instance string) {
+ query := `select timestamp from inactive where instance=$1`
+
+ rows, err := db.Query(query, instance)
+
+ CheckError(err, "error selecting instance from inactive")
+
+ var timeStamp string
+ defer rows.Close()
+ rows.Next()
+ rows.Scan(&timeStamp)
+
+ if timeStamp == "" {
+ query := `insert into inactive (instance, timestamp) values ($1, $2)`
+
+ _, err := db.Exec(query, instance, time.Now().UTC().Format(time.RFC3339))
+
+ CheckError(err, "error inserting instance to inactive")
+ } else {
+ if IsInactiveTimestamp(db, timeStamp) {
+ query := `delete from following where following like $1`
+ _, err:= db.Exec(query, "%" + instance + "%")
+
+ CheckError(err, "error deleting inactive instance following")
+
+ query = `delete from follower where follower like $1`
+ _, err= db.Exec(query, "%" + instance + "%")
+
+ CheckError(err, "error deleting inactive instance follower")
+
+ DeleteInstanceFromInactiveDB(db, instance)
+ }
+ }
+}
+
+func DeleteInstanceFromInactiveDB(db *sql.DB, instance string) {
+ query := `delete from inactive where instance=$1`
+
+ _, err := db.Exec(query, instance)
+
+ CheckError(err, "error deleting instance in inactive")
+}
+
+func IsInactiveTimestamp(db *sql.DB, timeStamp string) bool {
+ stamp, _ := time.Parse(time.RFC3339, timeStamp)
+ if time.Now().Sub(stamp).Hours() > 24 {
+ return true
+ }
+
+ return false
+}