From 4450e8da252137b68f067dbc9cfaa5745a8804c5 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 1 Aug 2021 18:35:00 -0700 Subject: fix inactive instance check and archive bug --- client.go | 5 +++-- database.go | 3 +-- main.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++------ static/archive.html | 12 +++++------ static/faq.html | 2 +- static/npost.html | 1 + 6 files changed, 63 insertions(+), 17 deletions(-) diff --git a/client.go b/client.go index 5ccdade..3b7676e 100644 --- a/client.go +++ b/client.go @@ -1019,7 +1019,7 @@ func ShortExcerpt(post ObjectBase) string { var returnString string if post.Name != "" { - returnString = post.Name + ": " + post.Content; + returnString = post.Name + "| " + post.Content; } else { returnString = post.Content; } @@ -1032,12 +1032,13 @@ func ShortExcerpt(post ObjectBase) string { returnString = match[0] + "..." } - re = regexp.MustCompile(`(^.+:)`) + re = regexp.MustCompile(`(^.+\|)`) match = re.FindStringSubmatch(returnString) if len(match) > 0 { returnString = strings.Replace(returnString, match[0], "" + match[0] + "", 1) + returnString = strings.Replace(returnString, "|", ":", 1) } return returnString diff --git a/database.go b/database.go index d0b6fcc..f142ea2 100644 --- a/database.go +++ b/database.go @@ -1834,7 +1834,7 @@ func IsInactiveTimestamp(db *sql.DB, timeStamp string) bool { } func ArchivePosts(db *sql.DB, actor Actor) { - if actor.Id != "" { + if actor.Id != "" && actor.Id != Domain { col := GetAllActorArchiveDB(db, actor.Id, 165) for _, e := range col.OrderedItems { for _, k := range e.Replies.OrderedItems { @@ -1901,7 +1901,6 @@ func GetActorCollectionDBType(db *sql.DB, actorId string, nType string) Collecti post.Replies = &replies post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCount(db, post) - post.Attachment = GetObjectAttachment(db, attachID) post.Preview = GetObjectPreview(db, previewID) diff --git a/main.go b/main.go index c370722..07d2adf 100644 --- a/main.go +++ b/main.go @@ -71,6 +71,8 @@ func main() { StartupArchive(db) + go CheckInactive(db) + Boards = GetBoardCollection(db) // root actor is used to follow remote feeds that are not local @@ -1864,7 +1866,6 @@ func GetActor(id string) Actor { resp, err := RouteProxy(req) if err != nil { - fmt.Println("error with getting actor resp " + id) return respActor } @@ -1874,7 +1875,9 @@ func GetActor(id string) Actor { err = json.Unmarshal(body, &respActor) - CheckError(err, "error getting actor from body") + if err != nil { + return respActor + } ActorCache[actor + "@" + instance] = respActor } @@ -2213,10 +2216,7 @@ func MakeActivityRequest(db *sql.DB, activity Activity) { _, err = RouteProxy(req) if err != nil { - fmt.Println("error with sending activity resp to actor " + instance + " instance marked as inactive and will be removed from following and followers in 24 hrs") - AddInstanceToInactiveDB(db, instance) - } else { - DeleteInstanceFromInactiveDB(db, instance) + fmt.Println("error with sending activity resp to actor " + instance) } } } @@ -2942,3 +2942,48 @@ func StartupArchive(db *sql.DB) { ArchivePosts(db, GetActorFromDB(db, e.Id)) } } + +func CheckInactive(db *sql.DB) { + for true { + CheckInactiveInstances(db) + time.Sleep(48 * time.Hour) + } +} + +func CheckInactiveInstances(db *sql.DB) map[string]string { + instances := make(map[string]string) + query := `select following from following` + rows, err := db.Query(query) + + CheckError(err, "cold not select instances from following") + + defer rows.Close() + for rows.Next() { + var instance string + rows.Scan(&instance) + instances[instance] = instance + } + + query = `select follower from follower` + rows, err = db.Query(query) + + CheckError(err, "cold not select instances from follower") + + defer rows.Close() + for rows.Next() { + var instance string + rows.Scan(&instance) + instances[instance] = instance + } + + for _, e := range instances { + actor := GetActor(e) + if actor.Id == "" { + AddInstanceToInactiveDB(db, e) + } else { + DeleteInstanceFromInactiveDB(db, e) + } + } + + return instances +} diff --git a/static/archive.html b/static/archive.html index aa37c94..b08693a 100644 --- a/static/archive.html +++ b/static/archive.html @@ -37,14 +37,14 @@
- +
{{ if eq $board.ModCred $board.Domain $board.Actor.Id }} - + {{ end }} - + - + {{ range $i, $e := .Posts }} {{ if mod $i 2 }} @@ -53,7 +53,7 @@ {{ end }} - + {{ else }} @@ -62,7 +62,7 @@ {{ end }} - + {{ end }} diff --git a/static/faq.html b/static/faq.html index f4fb237..b9c6085 100644 --- a/static/faq.html +++ b/static/faq.html @@ -56,7 +56,7 @@

Soon™.

What version is this FChannel instance?

-

v0.0.14-release

+

v0.0.14-dev

[Home][Rules][FAQ] diff --git a/static/npost.html b/static/npost.html index b0f89e6..2f0778f 100644 --- a/static/npost.html +++ b/static/npost.html @@ -50,6 +50,7 @@ {{ end }} {{ define "script" }} + {{ end }} -- cgit v1.2.3
No.No. Excerpt
[Pop]{{ short $board.Actor.Outbox $e.Id }}{{ shortExcerpt $e }}{{ shortExcerpt $e }} [View]
[Pop]{{ short $board.Actor.Outbox $e.Id }}{{ shortExcerpt $e }}{{ shortExcerpt $e }} [View]