all repos — honk @ a8ba88aaf9a3f729638ed8bb35538139a0e01aa6

my fork of honk

no wonder caching is a bad idea, honks mutate... make a copy.
Ted Unangst tedu@tedunangst.com
Wed, 30 Oct 2019 00:32:23 -0400
commit

a8ba88aaf9a3f729638ed8bb35538139a0e01aa6

parent

a1d0514f09e23db62c89c08bb579afb868d73689

1 files changed, 12 insertions(+), 2 deletions(-)

jump to
M database.godatabase.go

@@ -220,6 +220,16 @@

var mehonks = make(map[int64][]*Honk) var melock sync.Mutex +func copyhonks(honks []*Honk) []*Honk { + rv := make([]*Honk, len(honks)) + for i, h := range honks { + dupe := new(Honk) + *dupe = *h + rv[i] = dupe + } + return rv +} + func gethonksforme(userid int64, wanted int64) []*Honk { if wanted > 0 { dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat)

@@ -234,7 +244,7 @@ if len(honks) == 0 {

dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat) rows, err := stmtHonksForMe.Query(wanted, userid, dt, userid) honks = getsomehonks(rows, err) - mehonks[userid] = honks + mehonks[userid] = copyhonks(honks) return honks } wanted = honks[0].ID

@@ -245,7 +255,7 @@ honks = append(honks, mehonks[userid]...)

if len(honks) > 250 { honks = honks[:250] } - mehonks[userid] = honks + mehonks[userid] = copyhonks(honks) return honks } func getsavedhonks(userid int64, wanted int64) []*Honk {