Skip to content

Commit

Permalink
add outgoing posts graph
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Jun 6, 2023
1 parent 5214cb4 commit 5531df2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/garbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

const (
notesTTL = time.Hour * 24 * 30
deliveryTTL = time.Hour * 24
deliveryTTL = time.Hour * 24 * 7
)

func CollectGarbage(ctx context.Context, db *sql.DB) error {
Expand Down
4 changes: 4 additions & 0 deletions data/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func Migrate(ctx context.Context, db *sql.DB) error {
return err
}

if _, err := db.ExecContext(ctx, `CREATE INDEX IF NOT EXISTS deliveriesinserted ON deliveries(inserted)`); err != nil {
return err
}

if _, err := db.ExecContext(ctx, `CREATE INDEX IF NOT EXISTS hashtagshashtag ON hashtags(hashtag)`); err != nil {
return err
}
Expand Down
13 changes: 13 additions & 0 deletions front/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func getWeeklyPostsGraph(r *request) string {
return getGraph(r, `select strftime('%Y-%m-%d', datetime(inserted*60*60*24, 'unixepoch')), count(*) from (select inserted/(60*60*24) as inserted from notes where inserted>unixepoch()-60*60*24*7 and inserted<unixepoch()/(60*60*24)*(60*60*24)) group by inserted order by inserted`, keys, values)
}

func getWeeklyDeliveriesGraph(r *request) string {
keys := make([]string, 7)
values := make([]int64, 7)
return getGraph(r, `select strftime('%Y-%m-%d %H:%M', datetime(day*60*60*24, 'unixepoch')), count(*) from (select inserted/(60*60*24) as day from deliveries where inserted>unixepoch()-60*60*24*7 and inserted<unixepoch()/(60*60*24)*60*60*24) group by day order by day`, keys, values)
}

func getUsersGraph(r *request) string {
keys := make([]string, 24)
values := make([]int64, 24)
Expand Down Expand Up @@ -155,6 +161,7 @@ func stats(w text.Writer, r *request) {

dailyPostsGraph := getDailyPostsGraph(r)
weeklyPostsGraph := getWeeklyPostsGraph(r)
weeklyDeliveriesGraph := getWeeklyDeliveriesGraph(r)
usersGraph := getUsersGraph(r)
activeUsersGraph := getActiveUsersGraph(r)
instancesGraph := getInstancesGraph(r)
Expand All @@ -175,6 +182,12 @@ func stats(w text.Writer, r *request) {
w.Empty()
}

if weeklyDeliveriesGraph != "" {
w.Subtitle("Outgoing Posts Per Day")
w.Raw("Outgoing posts graph", weeklyDeliveriesGraph)
w.Empty()
}

if usersGraph != "" {
w.Subtitle("New Federated Users Per Hour")
w.Raw("Users graph", usersGraph)
Expand Down

0 comments on commit 5531df2

Please sign in to comment.