cache users table

This commit is contained in:
Ted Unangst 2019-10-07 15:29:34 -04:00
parent 2fc3103ad4
commit cd99584ffa
2 changed files with 16 additions and 3 deletions

View File

@ -28,14 +28,26 @@ import (
"humungus.tedunangst.com/r/webs/login"
)
func butwhatabout(name string) (*WhatAbout, error) {
var someusers = cacheNew(cacheOptions { Filler: func(name string) (*WhatAbout, bool) {
row := stmtWhatAbout.QueryRow(name)
var user WhatAbout
user := new (WhatAbout)
var options string
err := row.Scan(&user.ID, &user.Name, &user.Display, &user.About, &user.Key, &options)
if err != nil {
return nil, false
}
user.URL = fmt.Sprintf("https://%s/%s/%s", serverName, userSep, user.Name)
user.SkinnyCSS = strings.Contains(options, " skinny ")
return &user, err
return user, true
}})
func butwhatabout(name string) (*WhatAbout, error) {
var user *WhatAbout
ok := someusers.Get(name, &user)
if !ok {
return nil, fmt.Errorf("no user: %s", name)
}
return user, nil
}
func gethonkers(userid int64) []*Honker {

1
web.go
View File

@ -734,6 +734,7 @@ func saveuser(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Printf("error bouting what: %s", err)
}
someusers.Clear(u.Username)
http.Redirect(w, r, "/account", http.StatusSeeOther)
}