accounts: add "record count", start searchable user cache

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.
This commit is contained in:
Harvey Tindall
2025-05-15 19:19:51 +01:00
parent da0dc7f1c0
commit ebff016b5d
13 changed files with 213 additions and 67 deletions
+52 -10
View File
@@ -337,8 +337,8 @@ func (app *appContext) PostNewUserFromInvite(nu NewUserData, req ConfirmationKey
// FIXME: figure these out in a nicer way? this relies on the current ordering,
// which may not be fixed.
if discordEnabled {
if req.completeContactMethods[0].User != nil {
discordUser = req.completeContactMethods[0].User.(*DiscordUser)
if req.completeContactMethods[0].User != nil {
discordUser = req.completeContactMethods[0].User.(*DiscordUser)
}
if telegramEnabled && req.completeContactMethods[1].User != nil {
telegramUser = req.completeContactMethods[1].User.(*TelegramUser)
@@ -894,7 +894,25 @@ func (app *appContext) userSummary(jfUser mediabrowser.User) respUser {
}
// @Summary Get a list of Jellyfin users.
// @Summary Returns the total number of Jellyfin users.
// @Produce json
// @Success 200 {object} PageCountDTO
// @Router /users/count [get]
// @Security Bearer
// @tags Activity
func (app *appContext) GetUserCount(gc *gin.Context) {
resp := PageCountDTO{}
err := app.userCache.Gen(app)
if err != nil {
app.err.Printf(lm.FailedGetUsers, lm.Jellyfin, err)
respond(500, "Couldn't get users", gc)
return
}
resp.Count = uint64(len(app.userCache.Cache))
gc.JSON(200, resp)
}
// @Summary Get a list of -all- Jellyfin users.
// @Produce json
// @Success 200 {object} getUsersDTO
// @Failure 500 {object} stringResponse
@@ -903,19 +921,43 @@ func (app *appContext) userSummary(jfUser mediabrowser.User) respUser {
// @tags Users
func (app *appContext) GetUsers(gc *gin.Context) {
var resp getUsersDTO
users, err := app.jf.GetUsers(false)
resp.UserList = make([]respUser, len(users))
// We're sending all users, so this is always true
resp.LastPage = true
err := app.userCache.Gen(app)
if err != nil {
app.err.Printf(lm.FailedGetUsers, lm.Jellyfin, err)
respond(500, "Couldn't get users", gc)
return
}
i := 0
for _, jfUser := range users {
user := app.userSummary(jfUser)
resp.UserList[i] = user
i++
resp.UserList = app.userCache.Cache
gc.JSON(200, resp)
}
// @Summary Get a paginated, searchable list of Jellyfin users.
// @Produce json
// @Param getUsersReqDTO body getUsersReqDTO true "search / pagination parameters"
// @Success 200 {object} getUsersDTO
// @Failure 500 {object} stringResponse
// @Router /users [post]
// @Security Bearer
// @tags Users
func (app *appContext) SearchUsers(gc *gin.Context) {
req := getUsersReqDTO{}
gc.BindJSON(&req)
// FIXME: Figure out how to search, sort and paginate []mediabrowser.User!
// Expr!
var resp getUsersDTO
// We're sending all users, so this is always true
resp.LastPage = true
err := app.userCache.Gen(app)
if err != nil {
app.err.Printf(lm.FailedGetUsers, lm.Jellyfin, err)
respond(500, "Couldn't get users", gc)
return
}
resp.UserList = app.userCache.Cache
gc.JSON(200, resp)
}