From b360a01719e379f859034a5ac25bc03ac26bb2c2 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Mon, 28 Aug 2023 01:10:27 -0400 Subject: [PATCH] factor out 7 day honkwindow, from zev --- database.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/database.go b/database.go index afbf133..dacca18 100644 --- a/database.go +++ b/database.go @@ -36,6 +36,8 @@ import ( "humungus.tedunangst.com/r/webs/mz" ) +var honkwindow time.Duration = 7 * 24 * time.Hour + //go:embed schema.sql var sqlSchema string @@ -187,7 +189,7 @@ func getbonk(userid int64, xid string) *Honk { } func getpublichonks() []*Honk { - dt := time.Now().Add(-7 * 24 * time.Hour).UTC().Format(dbtimeformat) + dt := time.Now().Add(-honkwindow).UTC().Format(dbtimeformat) rows, err := stmtPublicHonks.Query(dt, 100) return getsomehonks(rows, err) } @@ -223,7 +225,7 @@ func geteventhonks(userid int64) []*Honk { return honks } func gethonksbyuser(name string, includeprivate bool, wanted int64) []*Honk { - dt := time.Now().Add(-7 * 24 * time.Hour).UTC().Format(dbtimeformat) + dt := time.Now().Add(-honkwindow).UTC().Format(dbtimeformat) limit := 50 whofore := 2 if includeprivate { @@ -233,18 +235,18 @@ func gethonksbyuser(name string, includeprivate bool, wanted int64) []*Honk { return getsomehonks(rows, err) } func gethonksforuser(userid int64, wanted int64) []*Honk { - dt := time.Now().Add(-7 * 24 * time.Hour).UTC().Format(dbtimeformat) + dt := time.Now().Add(-honkwindow).UTC().Format(dbtimeformat) rows, err := stmtHonksForUser.Query(wanted, userid, dt, userid, userid) return getsomehonks(rows, err) } func gethonksforuserfirstclass(userid int64, wanted int64) []*Honk { - dt := time.Now().Add(-7 * 24 * time.Hour).UTC().Format(dbtimeformat) + dt := time.Now().Add(-honkwindow).UTC().Format(dbtimeformat) rows, err := stmtHonksForUserFirstClass.Query(wanted, userid, dt, userid, userid) return getsomehonks(rows, err) } func gethonksforme(userid int64, wanted int64) []*Honk { - dt := time.Now().Add(-7 * 24 * time.Hour).UTC().Format(dbtimeformat) + dt := time.Now().Add(-honkwindow).UTC().Format(dbtimeformat) rows, err := stmtHonksForMe.Query(wanted, userid, dt, userid, 250) return getsomehonks(rows, err) }