ebff016b5d
RecordCounter class created from that in activityList, and put in
accountsList. PageCount-type route standardized and made for /users
(/users/count). Created userCache, which regularly generates the
respUser list returned by /users. Added a currently dumb POST /users for
searching/pagination, GET /users is now just for getting -all- users.
go-getted expr, an expression language that seems like it'll be useful
for evaluating local searches. We don't store this data in the badger
DB, so we can't use the nice query form provided by badgerhold.
36 lines
622 B
Go
36 lines
622 B
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
// FIXME: Follow mediabrowser, or make tuneable, or both
|
|
WEB_USER_CACHE_SYNC = 30 * time.Second
|
|
)
|
|
|
|
type UserCache struct {
|
|
Cache []respUser
|
|
LastSync time.Time
|
|
Lock sync.Mutex
|
|
}
|
|
|
|
func (c *UserCache) Gen(app *appContext) error {
|
|
if !time.Now().After(c.LastSync.Add(WEB_USER_CACHE_SYNC)) {
|
|
return nil
|
|
}
|
|
users, err := app.jf.GetUsers(false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.Lock.Lock()
|
|
c.Cache = make([]respUser, len(users))
|
|
for i, jfUser := range users {
|
|
c.Cache[i] = app.userSummary(jfUser)
|
|
}
|
|
c.LastSync = time.Now()
|
|
c.Lock.Unlock()
|
|
return nil
|
|
}
|