Fix #4601: Hide deleted pools by default in pool search.

* On /pools, hide deleted pools by default in HTML responses. Don't
  filter out deleted pools in API responses.

* API change: on /forum_topics, only hide deleted forum topics by
  default for HTML responses, not for API responses. Explicitly do
  https://danbooru.donmai.us/forum_topics.json?search[is_deleted]=false
  to filter out deleted topics.

* API change: on /tags, only hide empty tags by default for HTML
  responses, not for API responses. Explicitly do
  https://danbooru.donmai.us/tags.json?search[is_empty]=false to filter
  out empty tags.

* API change: on /pools, default to 20 posts per page for API responses,
  not 40.

* API change: add `search[is_empty]` param to /tags.json endpoint.
  `search[hide_empty]=true` is deprecated in favor of `search[is_empty]=false`.

* On /pools, add option to show/hide deleted pools in search form.

* Fix the /forum_topics page putting `search[order]=sticky&limit=40` in
  the URL when browsing past page 1.
This commit is contained in:
evazion
2021-09-29 05:28:21 -05:00
parent 4a525c7473
commit 2eb89a8354
8 changed files with 49 additions and 23 deletions

View File

@@ -14,12 +14,21 @@ class ApplicationRecord < ActiveRecord::Base
extending(PaginationExtension).paginate(*args, **options)
end
def paginated_search(params, count_pages: params[:search].present?, **defaults)
# Perform a search using the model's `search` method, then paginate the results.
#
# params [Hash] The URL request params from the user
# page [Integer] The page number
# limit [Integer] The number of posts per page
# count_pages [Boolean] If true, show the exact number of pages of
# results. If false (the default), don't count the exact number of pages
# of results; assume there are too many pages to count.
# defaults [Hash] The default params for the search
def paginated_search(params, page: params[:page], limit: params[:limit], count_pages: params[:search].present?, defaults: {})
search_params = params.fetch(:search, {}).permit!
search_params = defaults.merge(search_params).with_indifferent_access
max_limit = (params[:format] == "sitemap") ? 10_000 : 1_000
search(search_params).paginate(params[:page], limit: params[:limit], max_limit: max_limit, search_count: count_pages)
search(search_params).paginate(page, limit: limit, max_limit: max_limit, search_count: count_pages)
end
end
end