can use the cache functions for handles now
This commit is contained in:
parent
0731de07fa
commit
3b70052f3d
|
@ -262,8 +262,8 @@ func eradicatexonk(userid int64, xid string) {
|
|||
|
||||
func savexonk(x *Honk) {
|
||||
log.Printf("saving xonk: %s", x.XID)
|
||||
go prehandle(x.Honker)
|
||||
go prehandle(x.Oonker)
|
||||
go handles(x.Honker)
|
||||
go handles(x.Oonker)
|
||||
savehonk(x)
|
||||
}
|
||||
|
||||
|
|
58
fun.go
58
fun.go
|
@ -487,36 +487,13 @@ func originate(u string) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
var allhandles = make(map[string]string)
|
||||
var handlelock sync.Mutex
|
||||
|
||||
// handle, handle@host
|
||||
func handles(xid string) (string, string) {
|
||||
if xid == "" {
|
||||
return "", ""
|
||||
}
|
||||
handlelock.Lock()
|
||||
handle := allhandles[xid]
|
||||
handlelock.Unlock()
|
||||
if handle == "" {
|
||||
handle = findhandle(xid)
|
||||
handlelock.Lock()
|
||||
allhandles[xid] = handle
|
||||
handlelock.Unlock()
|
||||
}
|
||||
if handle == xid {
|
||||
return xid, xid
|
||||
}
|
||||
return handle, handle + "@" + originate(xid)
|
||||
}
|
||||
|
||||
func findhandle(xid string) string {
|
||||
var allhandles = cache.New(cache.Options{Filler: func(xid string) (string, bool) {
|
||||
row := stmtGetXonker.QueryRow(xid, "handle")
|
||||
var handle string
|
||||
err := row.Scan(&handle)
|
||||
if err != nil {
|
||||
info, _ := investigate(xid)
|
||||
if info == nil {
|
||||
info, err := investigate(xid)
|
||||
if err != nil {
|
||||
m := re_unurl.FindStringSubmatch(xid)
|
||||
if len(m) > 2 {
|
||||
handle = m[2]
|
||||
|
@ -525,21 +502,26 @@ func findhandle(xid string) string {
|
|||
}
|
||||
} else {
|
||||
handle = info.Name
|
||||
}
|
||||
_, err = stmtSaveXonker.Exec(xid, handle, "handle")
|
||||
if err != nil {
|
||||
log.Printf("error saving handle: %s", err)
|
||||
_, err = stmtSaveXonker.Exec(xid, handle, "handle")
|
||||
if err != nil {
|
||||
log.Printf("error saving handle: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return handle
|
||||
}
|
||||
return handle, true
|
||||
}})
|
||||
|
||||
var handleprelock sync.Mutex
|
||||
|
||||
func prehandle(xid string) {
|
||||
handleprelock.Lock()
|
||||
defer handleprelock.Unlock()
|
||||
handles(xid)
|
||||
// handle, handle@host
|
||||
func handles(xid string) (string, string) {
|
||||
if xid == "" {
|
||||
return "", ""
|
||||
}
|
||||
var handle string
|
||||
allhandles.Get(xid, &handle)
|
||||
if handle == xid {
|
||||
return xid, xid
|
||||
}
|
||||
return handle, handle + "@" + originate(xid)
|
||||
}
|
||||
|
||||
func prepend(s string, x []string) []string {
|
||||
|
|
Loading…
Reference in New Issue