all repos — honk @ 0c94d295a84efc76854b820b0e5313890872e8b9

my fork of honk

a cache for handles
Ted Unangst tedu@tedunangst.com
Fri, 16 Aug 2019 00:11:30 -0400
commit

0c94d295a84efc76854b820b0e5313890872e8b9

parent

3cef9262a56518f7484be1f4553b5233c5926bbe

1 files changed, 21 insertions(+), 4 deletions(-)

jump to
M fun.gofun.go

@@ -374,8 +374,28 @@ }

return "" } +var allhandles = make(map[string]string) +var handlelock sync.Mutex + // handle, handle@host func handles(xid string) (string, string) { + 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 { + log.Printf("finding") row := stmtGetXonker.QueryRow(xid, "handle") var handle string err := row.Scan(&handle)

@@ -396,10 +416,7 @@ if err != nil {

log.Printf("error saving handle: %s", err) } } - if handle == xid { - return xid, xid - } - return handle, handle + "@" + originate(xid) + return handle } func prepend(s string, x []string) []string {