@ -283,55 +283,7 @@ func gethonksbyconvoy(userid int64, convoy string, wanted int64) []*Honk {
return honks
}
func gethonksbysearch ( userid int64 , q string , wanted int64 ) [ ] * Honk {
var queries [ ] string
var params [ ] interface { }
queries = append ( queries , "honks.honkid > ?" )
params = append ( params , wanted )
queries = append ( queries , "honks.userid = ?" )
params = append ( params , userid )
terms := strings . Split ( q , " " )
for _ , t := range terms {
if t == "" {
continue
}
negate := " "
if t [ 0 ] == '-' {
t = t [ 1 : ]
negate = " not "
}
if t == "" {
continue
}
if strings . HasPrefix ( t , "site:" ) {
site := t [ 5 : ]
site = "%" + site + "%"
queries = append ( queries , "xid" + negate + "like ?" )
params = append ( params , site )
continue
}
if strings . HasPrefix ( t , "honker:" ) {
honker := t [ 7 : ]
xid := fullname ( honker , userid )
if xid != "" {
honker = xid
}
queries = append ( queries , negate + "(honks.honker = ? or honks.oonker = ?)" )
params = append ( params , honker )
params = append ( params , honker )
continue
}
t = "%" + t + "%"
queries = append ( queries , "noise" + negate + "like ?" )
params = append ( params , t )
}
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 "
where := "where " + strings . Join ( queries , " and " )
butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)"
limit := " order by honks.honkid desc limit 250"
params = append ( params , userid )
rows , err := opendatabase ( ) . Query ( selecthonks + where + butnotthose + limit , params ... )
rows , err := stmtHonksBySearch . Query ( q , userid , userid )
honks := getsomehonks ( rows , err )
return honks
}
@ -1136,6 +1088,7 @@ var stmtSaveChonk, stmtLoadChonks, stmtGetChatters *sql.Stmt
var stmtGetUserCount * sql . Stmt
var stmtGetActiveUserCount * sql . Stmt
var stmtGetLocalHonkCount * sql . Stmt
var stmtHonksBySearch * sql . Stmt
func preparetodie ( db * sql . DB , s string ) * sql . Stmt {
stmt , err := db . Prepare ( s )
@ -1155,10 +1108,10 @@ func prepareStatements(db *sql.DB) {
stmtDubbers = preparetodie ( db , "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'" )
stmtNamedDubbers = preparetodie ( db , "select honkerid, userid, name, xid, flavor from honkers where userid = ? and name = ? and flavor = 'dub'" )
selecthonks := "select honks.honkid, honks.userid, username, what, honk er, 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, honk s.honk er, oonker, honks.xid, rid, dt, url, audience, honks. noise, precis, format, honks. convoy, whofore, flags from honks join users on honks.userid = users.userid "
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 honks. 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 = ?" )
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" )
@ -1224,4 +1177,5 @@ func prepareStatements(db *sql.DB) {
stmtGetUserCount = preparetodie ( db , "select count(*) from users where userid > 0" )
stmtGetActiveUserCount = preparetodie ( db , "select count(distinct honker) from honks where whofore = 2 and dt > ?" )
stmtGetLocalHonkCount = preparetodie ( db , "select count(*) from honks where whofore = 2" )
stmtHonksBySearch = preparetodie ( db , selecthonks + " join altavista on honks.honkid = altavista.rowid where altavista match ? and honks.userid = ? " + butnotthose + limit )
}