0.1.38 gateway
This commit is contained in:
@@ -18,6 +18,33 @@ type MediaRequest struct {
|
||||
RequestedAt time.Time `json:"requestedAt"`
|
||||
}
|
||||
|
||||
// RequestUsage is the operator-facing use of the request feature. A recorded request is
|
||||
// one that Memby has already handed to Radarr or Sonarr; their later download state is
|
||||
// deliberately not duplicated here.
|
||||
type RequestUsage struct {
|
||||
UserID string `json:"userId"`
|
||||
Requests int64 `json:"requests"`
|
||||
LastRequest time.Time `json:"lastRequest,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Store) RequestUsage(ctx context.Context) ([]RequestUsage, error) {
|
||||
rows, err := s.pool.Query(ctx, `SELECT emby_user_id, count(*), max(requested_at)
|
||||
FROM media_requests GROUP BY emby_user_id`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("store: request usage: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []RequestUsage{}
|
||||
for rows.Next() {
|
||||
var value RequestUsage
|
||||
if err := rows.Scan(&value.UserID, &value.Requests, &value.LastRequest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, value)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// MediaRequestLimit caps what one viewer's page will read back. A household that has been
|
||||
// asking for things for two years should not turn the page into an unbounded query, and
|
||||
// nobody scrolls past the most recent hundred by remote.
|
||||
|
||||
Reference in New Issue
Block a user