22efdf9121e5 — Zev Weiss 2 months ago
De-hardcode time duration for honk display
1 files changed, 7 insertions(+), 5 deletions(-)

M database.go
M database.go +7 -5
@@ 35,6 35,8 @@ import (
 	"humungus.tedunangst.com/r/webs/mz"
 )
 
+const honkwindow time.Duration = 7 * 24 * time.Hour
+
 //go:embed schema.sql
 var sqlSchema string
 

          
@@ 186,7 188,7 @@ func getbonk(userid int64, xid string) *
 }
 
 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)
 }

          
@@ 222,7 224,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 {

          
@@ 232,18 234,18 @@ func gethonksbyuser(name string, include
 	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)
 	return getsomehonks(rows, err)
 }