Implement IVFFLAT probe settings and enhance post/user controllers

- Added a new method `set_ivfflat_probes!` in `ApplicationController` to configure IVFFLAT probe settings.
- Integrated `set_ivfflat_probes!` as a before action in `Domain::Fa::PostsController` and `Domain::Fa::UsersController` for the `show` action.
- Updated `set_domain_fa_post` method to include the `response` association in the post query.
- Increased the limit of similar posts displayed from 5 to 20 and included the creator's avatar in the post includes for better data retrieval.
This commit is contained in:
Dylan Knutson
2024-12-30 00:37:09 +00:00
parent af119ed683
commit eb5a6d3190
4 changed files with 14 additions and 3 deletions

View File

@@ -12,6 +12,13 @@ class ApplicationController < ActionController::Base
# Pundit authorization error handling
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
protected
def set_ivfflat_probes!
ReduxApplicationRecord.connection.execute("SET ivfflat.max_probes = 10")
ReduxApplicationRecord.connection.execute("SET ivfflat.probes = 10")
end
private
def user_not_authorized

View File

@@ -1,4 +1,5 @@
class Domain::Fa::PostsController < ApplicationController
before_action :set_ivfflat_probes!, only: %i[show]
before_action :set_domain_fa_post, only: %i[show scan_post]
skip_before_action :verify_authenticity_token,
@@ -130,6 +131,8 @@ class Domain::Fa::PostsController < ApplicationController
# Use callbacks to share common setup or constraints between actions.
def set_domain_fa_post
@post =
Domain::Fa::Post.includes(:creator, :file).find_by_fa_id!(params[:fa_id])
Domain::Fa::Post.includes(:creator, file: :response).find_by_fa_id!(
params[:fa_id],
)
end
end

View File

@@ -1,4 +1,5 @@
class Domain::Fa::UsersController < ApplicationController
before_action :set_ivfflat_probes!, only: %i[show]
before_action :set_user, only: %i[show]
skip_before_action :authenticate_user!, only: %i[show]

View File

@@ -8,8 +8,8 @@
post
.disco
&.nearest_neighbors(:for_favorite, distance: "cosine")
&.limit(5)
&.includes(:post) %>
&.limit(20)
&.includes(post: { creator: :avatar }) %>
<% if similar %>
<% similar
.map(&:post)