try a little harder to remember follow ids

This commit is contained in:
Ted Unangst 2020-09-14 14:59:45 -04:00
parent 68ee7dece2
commit f3a9f7711a
3 changed files with 21 additions and 13 deletions

View File

@ -1702,7 +1702,9 @@ func updateMe(username string) {
} }
func followme(user *WhatAbout, who string, name string, j junk.Junk) { func followme(user *WhatAbout, who string, name string, j junk.Junk) {
log.Printf("updating honker follow: %s", who) folxid, _ := j.GetString("id")
log.Printf("updating honker follow: %s %s", who, folxid)
var x string var x string
db := opendatabase() db := opendatabase()
@ -1710,19 +1712,21 @@ func followme(user *WhatAbout, who string, name string, j junk.Junk) {
err := row.Scan(&x) err := row.Scan(&x)
if err != sql.ErrNoRows { if err != sql.ErrNoRows {
log.Printf("duplicate follow request: %s", who) log.Printf("duplicate follow request: %s", who)
_, err = stmtUpdateFlavor.Exec("dub", user.ID, name, who, "undub") _, err = stmtUpdateFlavor.Exec("dub", folxid, user.ID, name, who, "undub")
if err != nil { if err != nil {
log.Printf("error updating honker: %s", err) log.Printf("error updating honker: %s", err)
} }
} else { } else {
stmtSaveDub.Exec(user.ID, name, who, "dub") stmtSaveDub.Exec(user.ID, name, who, "dub", folxid)
} }
go rubadubdub(user, j) go rubadubdub(user, j)
} }
func unfollowme(user *WhatAbout, who string, name string, j junk.Junk) { func unfollowme(user *WhatAbout, who string, name string, j junk.Junk) {
log.Printf("updating honker undo: %s", who) folxid, _ := j.GetString("id")
_, err := stmtUpdateFlavor.Exec("undub", user.ID, name, who, "dub")
log.Printf("updating honker undo: %s %s", who, folxid)
_, err := stmtUpdateFlavor.Exec("undub", folxid, user.ID, name, who, "dub")
if err != nil { if err != nil {
log.Printf("error updating honker: %s", err) log.Printf("error updating honker: %s", err)
return return
@ -1772,16 +1776,16 @@ func followyou2(user *WhatAbout, j junk.Junk) {
who, _ := j.GetString("actor") who, _ := j.GetString("actor")
log.Printf("updating honker accept: %s", who) log.Printf("updating honker accept: %s", who)
var name string
db := opendatabase() db := opendatabase()
row := db.QueryRow("select name from honkers where userid = ? and xid = ? and flavor in ('presub')", row := db.QueryRow("select name, folxid from honkers where userid = ? and xid = ? and flavor in ('presub')",
user.ID, who) user.ID, who)
err := row.Scan(&name) var name, folxid string
err := row.Scan(&name, &folxid)
if err != nil { if err != nil {
log.Printf("can't get honker name: %s", err) log.Printf("can't get honker name: %s", err)
return return
} }
_, err = stmtUpdateFlavor.Exec("sub", user.ID, name, who, "presub") _, err = stmtUpdateFlavor.Exec("sub", folxid, user.ID, name, who, "presub")
if err != nil { if err != nil {
log.Printf("error updating honker: %s", err) log.Printf("error updating honker: %s", err)
return return

View File

@ -883,7 +883,7 @@ func preparetodie(db *sql.DB, s string) *sql.Stmt {
func prepareStatements(db *sql.DB) { func prepareStatements(db *sql.DB) {
stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor, combos, meta from honkers where userid = ? and (flavor = 'presub' or flavor = 'sub' or flavor = 'peep' or flavor = 'unsub') order by name") stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor, combos, meta from honkers where userid = ? and (flavor = 'presub' or flavor = 'sub' or flavor = 'peep' or flavor = 'unsub') order by name")
stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, ?, ?, ?, '')") stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, ?, ?, ?, '')")
stmtUpdateFlavor = preparetodie(db, "update honkers set flavor = ? where userid = ? and name = ? and xid = ? and flavor = ?") stmtUpdateFlavor = preparetodie(db, "update honkers set flavor = ?, folxid = ? where userid = ? and name = ? and xid = ? and flavor = ?")
stmtUpdateHonker = preparetodie(db, "update honkers set name = ?, combos = ?, meta = ? where honkerid = ? and userid = ?") stmtUpdateHonker = preparetodie(db, "update honkers set name = ?, combos = ?, meta = ? where honkerid = ? and userid = ?")
stmtOneHonker = preparetodie(db, "select xid from honkers where name = ? and userid = ?") stmtOneHonker = preparetodie(db, "select xid from honkers where name = ? and userid = ?")
stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'") stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'")
@ -929,7 +929,7 @@ func prepareStatements(db *sql.DB) {
stmtFindFile = preparetodie(db, "select fileid, xid from filemeta where url = ? and local = 1") stmtFindFile = preparetodie(db, "select fileid, xid from filemeta where url = ? and local = 1")
stmtUserByName = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where username = ? and userid > 0") stmtUserByName = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where username = ? and userid > 0")
stmtUserByNumber = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where userid = ?") stmtUserByNumber = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where userid = ?")
stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, '', '', '', '')") stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, '', '', '', ?)")
stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, userid, rcpt, msg) values (?, ?, ?, ?, ?)") stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, userid, rcpt, msg) values (?, ?, ?, ?, ?)")
stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers") stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers")
stmtLoadDoover = preparetodie(db, "select tries, userid, rcpt, msg from doovers where dooverid = ?") stmtLoadDoover = preparetodie(db, "select tries, userid, rcpt, msg from doovers where dooverid = ?")

View File

@ -23,7 +23,7 @@ import (
"time" "time"
) )
var myVersion = 38 var myVersion = 39
type dbexecer interface { type dbexecer interface {
Exec(query string, args ...interface{}) (sql.Result, error) Exec(query string, args ...interface{}) (sql.Result, error)
@ -164,6 +164,10 @@ func upgradedb() {
doordie(db, "update config set value = 38 where key = 'dbversion'") doordie(db, "update config set value = 38 where key = 'dbversion'")
fallthrough fallthrough
case 38: case 38:
doordie(db, "update honkers set folxid = abs(random())")
doordie(db, "update config set value = 39 where key = 'dbversion'")
fallthrough
case 39:
default: default:
log.Fatalf("can't upgrade unknown version %d", dbversion) log.Fatalf("can't upgrade unknown version %d", dbversion)