Files
danbooru/app/controllers/autocomplete_controller.rb
evazion cf13ab1540 autocomplete: render html server-side.
Render the HTML for autocomplete results server-side instead of in
Javascript. This is cleaner than building HTML in Javascript, but it may
hurt caching because the HTTP responses are larger.

Fixes #4698: user autocomplete contains links to /posts

Also fixes a bug where tag counts in the autocomplete menu were different
from tag counts displayed elsewhere because of differences in rounding.
2022-08-30 01:26:02 -05:00

20 lines
636 B
Ruby

# frozen_string_literal: true
class AutocompleteController < ApplicationController
respond_to :html, :xml, :json
def index
@query = params.dig(:search, :query)
@type = params.dig(:search, :type)
@limit = params.fetch(:limit, 10).to_i
@autocomplete = AutocompleteService.new(@query, @type, current_user: CurrentUser.user, limit: @limit)
@results = @autocomplete.autocomplete_results
@expires_in = @autocomplete.cache_duration
@public = @autocomplete.cache_publicly?
expires_in @expires_in, public: @public unless response.cache_control.present?
respond_with(@results, layout: false)
end
end