reduce number of honks on some pages

master
Ted Unangst 5 years ago
parent 0c0d44f444
commit 0a03f937ec

@ -166,11 +166,11 @@ func getbonk(userid int64, xid string) *Honk {
func getpublichonks() []*Honk { func getpublichonks() []*Honk {
dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat) dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat)
rows, err := stmtPublicHonks.Query(dt) rows, err := stmtPublicHonks.Query(dt, 25)
return getsomehonks(rows, err) return getsomehonks(rows, err)
} }
func geteventhonks(userid int64) []*Honk { func geteventhonks(userid int64) []*Honk {
rows, err := stmtEventHonks.Query(userid) rows, err := stmtEventHonks.Query(userid, 25)
honks := getsomehonks(rows, err) honks := getsomehonks(rows, err)
sort.Slice(honks, func(i, j int) bool { sort.Slice(honks, func(i, j int) bool {
var t1, t2 time.Time var t1, t2 time.Time
@ -199,10 +199,12 @@ func geteventhonks(userid int64) []*Honk {
func gethonksbyuser(name string, includeprivate bool, wanted int64) []*Honk { func gethonksbyuser(name string, includeprivate bool, wanted int64) []*Honk {
dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat) dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat)
whofore := 2 whofore := 2
limit := 25
if includeprivate { if includeprivate {
whofore = 3 whofore = 3
limit = 50
} }
rows, err := stmtUserHonks.Query(wanted, whofore, name, dt) rows, err := stmtUserHonks.Query(wanted, whofore, name, dt, limit)
return getsomehonks(rows, err) return getsomehonks(rows, err)
} }
func gethonksforuser(userid int64, wanted int64) []*Honk { func gethonksforuser(userid int64, wanted int64) []*Honk {
@ -712,13 +714,14 @@ func prepareStatements(db *sql.DB) {
selecthonks := "select honks.honkid, honks.userid, username, what, honker, oonker, honks.xid, rid, dt, url, audience, noise, precis, format, convoy, whofore, flags from honks join users on honks.userid = users.userid " selecthonks := "select honks.honkid, honks.userid, username, what, honker, oonker, honks.xid, rid, dt, url, audience, noise, precis, format, convoy, whofore, flags from honks join users on honks.userid = users.userid "
limit := " order by honks.honkid desc limit 250" limit := " order by honks.honkid desc limit 250"
smalllimit := " order by honks.honkid desc limit ?"
butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)" butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)"
stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?") stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?")
stmtAnyXonk = preparetodie(db, selecthonks+"where xid = ? order by honks.honkid asc") stmtAnyXonk = preparetodie(db, selecthonks+"where xid = ? order by honks.honkid asc")
stmtOneBonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ? and what = 'bonk' and whofore = 2") stmtOneBonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ? and what = 'bonk' and whofore = 2")
stmtPublicHonks = preparetodie(db, selecthonks+"where whofore = 2 and dt > ?"+limit) stmtPublicHonks = preparetodie(db, selecthonks+"where whofore = 2 and dt > ?"+smalllimit)
stmtEventHonks = preparetodie(db, selecthonks+"where (whofore = 2 or honks.userid = ?) and what = 'event'"+limit) stmtEventHonks = preparetodie(db, selecthonks+"where (whofore = 2 or honks.userid = ?) and what = 'event'"+smalllimit)
stmtUserHonks = preparetodie(db, selecthonks+"where honks.honkid > ? and (whofore = 2 or whofore = ?) and username = ? and dt > ?"+limit) stmtUserHonks = preparetodie(db, selecthonks+"where honks.honkid > ? and (whofore = 2 or whofore = ?) and username = ? and dt > ?"+smalllimit)
myhonkers := " and honker in (select xid from honkers where userid = ? and (flavor = 'sub' or flavor = 'peep' or flavor = 'presub') and combos not like '% - %')" myhonkers := " and honker in (select xid from honkers where userid = ? and (flavor = 'sub' or flavor = 'peep' or flavor = 'presub') and combos not like '% - %')"
stmtHonksForUser = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ?"+myhonkers+butnotthose+limit) stmtHonksForUser = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ?"+myhonkers+butnotthose+limit)
stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and (what <> 'tonk')"+myhonkers+butnotthose+limit) stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and (what <> 'tonk')"+myhonkers+butnotthose+limit)

@ -161,9 +161,6 @@ func showrss(w http.ResponseWriter, r *http.Request) {
} else { } else {
honks = getpublichonks() honks = getpublichonks()
} }
if len(honks) > 20 {
honks = honks[0:20]
}
reverbolate(-1, honks) reverbolate(-1, honks)
home := fmt.Sprintf("https://%s/", serverName) home := fmt.Sprintf("https://%s/", serverName)

Loading…
Cancel
Save