posts: optimize filetype: searches.

When searching posts by width, height, file size, or file extension, use the
values from the media_assets table rather than the posts table.

This makes filetype: searches faster because the file_ext is indexed on
the media assets table, but not on the posts table.

This paves the way for getting rid of the width, height, file_size, and
file_ext indexes on the posts table in the future. It's wasteful to
index these columns on both the posts table and the media assets table.
This commit is contained in:
evazion
2022-11-02 02:03:14 -05:00
parent 3ecc389995
commit e849d8f1c2
3 changed files with 26 additions and 30 deletions

View File

@@ -1075,7 +1075,7 @@ class Post < ApplicationRecord
when *AutocompleteService::POST_STATUSES
status_matches(value, current_user)
when *MediaAsset::FILE_TYPES
attribute_matches(value, :file_ext, :enum)
attribute_matches(value, "media_assets.file_ext", :enum).joins(:media_asset)
when *Post::RATINGS.values.map(&:downcase)
rating_matches(value)
when *Post::RATING_ALIASES.keys