Files
mgdigital f2dcbf98fc Reduce aggregations in web UI (#87)
Fix https://github.com/bitmagnet-io/bitmagnet/issues/85

- Accurate counts in the web UI will only be shown for the top-level filters; when deep-filtering, the counts will show a less than or equal sign: `≤`, indicating the number is a "maximum possible" rather than an accurate count; I'm still not sure about the UX aspect of showing the `≤` which could be confusing if you're not sure what it means, but I figured it's better than showing nothing at all - open to suggestions!
- A background process keeps the in-memory query cache warm for the top-level aggregations (by default every 10 minutes), allowing them to be served instantly
- The query cache TTL has been increased to 20 minutes; improved performance is preferable to seeing the most up-to-date information
- Pagination has been refactored to account for not knowing the total number of pages; internally the search engine will request 1 more item than it needs to know if there's a next page to advance to
- Some general refactoring of the web app
2023-12-21 16:08:38 +00:00

42 lines
1005 B
Go

package query
import (
"github.com/bitmagnet-io/bitmagnet/internal/model"
)
type SearchParams struct {
QueryString model.NullString
Limit model.NullUint
Offset model.NullUint
TotalCount model.NullBool
HasNextPage model.NullBool
Cached model.NullBool
}
func (s SearchParams) Option() Option {
var options []Option
if s.QueryString.Valid {
options = append(options, QueryString(s.QueryString.String), OrderByQueryStringRank())
}
if s.Limit.Valid {
options = append(options, Limit(s.Limit.Uint))
}
if s.Offset.Valid {
options = append(options, Offset(s.Offset.Uint))
}
if s.TotalCount.Valid {
options = append(options, WithTotalCount(s.TotalCount.Bool))
}
if s.HasNextPage.Valid {
options = append(options, WithHasNextPage(s.HasNextPage.Bool))
}
if s.Cached.Valid {
if s.Cached.Bool {
options = append(options, Cached())
} else {
options = append(options, CacheWarm())
}
}
return Options(options...)
}