fix: projects load by invite code slowly

This commit is contained in:
vilet.yy 2021-06-15 15:33:23 +08:00
parent 7c43f2d8fc
commit 818317c292
3 changed files with 84 additions and 74 deletions

View File

@ -61,6 +61,7 @@
#
# index_projects_on_forked_from_project_id (forked_from_project_id)
# index_projects_on_identifier (identifier)
# index_projects_on_invite_code (invite_code)
# index_projects_on_is_public (is_public)
# index_projects_on_lft (lft)
# index_projects_on_name (name)
@ -74,6 +75,7 @@
class Project < ApplicationRecord
include Matchable
include Publicable

View File

@ -33,7 +33,7 @@ class Projects::ApplyJoinService < ApplicationService
private
def project
@_project ||= Project.find_by('binary(invite_code) = ? ',"#{params[:code].to_s.strip}")
@_project ||= Project.find_by(invite_code: params[:code].to_s.strip)
end
def role_value

View File

@ -0,0 +1,8 @@
class AddInviteCodeIndexToProjects < ActiveRecord::Migration[5.2]
def change
add_index :projects, :invite_code
execute <<-SQL
ALTER TABLE projects MODIFY COLUMN invite_code VARCHAR(255) BINARY CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL;
SQL
end
end