Improve performance of User Agent Detail
This commit is contained in:
parent
c89449e611
commit
5be8f03747
7 changed files with 43 additions and 7 deletions
|
@ -22,6 +22,10 @@ module Spammable
|
||||||
delegate :ip_address, :user_agent, to: :user_agent_detail, allow_nil: true
|
delegate :ip_address, :user_agent, to: :user_agent_detail, allow_nil: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def submittable_as_spam_by?(current_user)
|
||||||
|
current_user && current_user.admin? && submittable_as_spam?
|
||||||
|
end
|
||||||
|
|
||||||
def submittable_as_spam?
|
def submittable_as_spam?
|
||||||
if user_agent_detail
|
if user_agent_detail
|
||||||
user_agent_detail.submittable? && current_application_settings.akismet_enabled
|
user_agent_detail.submittable? && current_application_settings.akismet_enabled
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
= link_to 'Close issue', issue_path(@issue, issue: { state_event: :close }, format: 'json'), data: {no_turbolink: true}, class: "btn-close #{issue_button_visibility(@issue, true)}", title: 'Close issue'
|
= link_to 'Close issue', issue_path(@issue, issue: { state_event: :close }, format: 'json'), data: {no_turbolink: true}, class: "btn-close #{issue_button_visibility(@issue, true)}", title: 'Close issue'
|
||||||
%li
|
%li
|
||||||
= link_to 'Edit', edit_namespace_project_issue_path(@project.namespace, @project, @issue)
|
= link_to 'Edit', edit_namespace_project_issue_path(@project.namespace, @project, @issue)
|
||||||
- if @issue.submittable_as_spam? && current_user.admin?
|
- if @issue.submittable_as_spam_by?(current_user)
|
||||||
%li
|
%li
|
||||||
= link_to 'Submit as spam', mark_as_spam_namespace_project_issue_path(@project.namespace, @project, @issue), method: :post, class: 'btn-spam', title: 'Submit as spam'
|
= link_to 'Submit as spam', mark_as_spam_namespace_project_issue_path(@project.namespace, @project, @issue), method: :post, class: 'btn-spam', title: 'Submit as spam'
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
- if can?(current_user, :update_issue, @issue)
|
- if can?(current_user, :update_issue, @issue)
|
||||||
= link_to 'Reopen issue', issue_path(@issue, issue: { state_event: :reopen }, format: 'json'), data: {no_turbolink: true}, class: "hidden-xs hidden-sm btn btn-grouped btn-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen issue'
|
= link_to 'Reopen issue', issue_path(@issue, issue: { state_event: :reopen }, format: 'json'), data: {no_turbolink: true}, class: "hidden-xs hidden-sm btn btn-grouped btn-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen issue'
|
||||||
= link_to 'Close issue', issue_path(@issue, issue: { state_event: :close }, format: 'json'), data: {no_turbolink: true}, class: "hidden-xs hidden-sm btn btn-grouped btn-close #{issue_button_visibility(@issue, true)}", title: 'Close issue'
|
= link_to 'Close issue', issue_path(@issue, issue: { state_event: :close }, format: 'json'), data: {no_turbolink: true}, class: "hidden-xs hidden-sm btn btn-grouped btn-close #{issue_button_visibility(@issue, true)}", title: 'Close issue'
|
||||||
- if @issue.submittable_as_spam? && current_user.admin?
|
- if @issue.submittable_as_spam_by?(current_user)
|
||||||
= link_to 'Submit as spam', mark_as_spam_namespace_project_issue_path(@project.namespace, @project, @issue), method: :post, class: 'hidden-xs hidden-sm btn btn-grouped btn-spam', title: 'Submit as spam'
|
= link_to 'Submit as spam', mark_as_spam_namespace_project_issue_path(@project.namespace, @project, @issue), method: :post, class: 'hidden-xs hidden-sm btn btn-grouped btn-spam', title: 'Submit as spam'
|
||||||
= link_to 'Edit', edit_namespace_project_issue_path(@project.namespace, @project, @issue), class: 'hidden-xs hidden-sm btn btn-grouped issuable-edit'
|
= link_to 'Edit', edit_namespace_project_issue_path(@project.namespace, @project, @issue), class: 'hidden-xs hidden-sm btn btn-grouped issuable-edit'
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
- if can?(current_user, :create_project_snippet, @project)
|
- if can?(current_user, :create_project_snippet, @project)
|
||||||
= link_to new_namespace_project_snippet_path(@project.namespace, @project), class: 'btn btn-grouped btn-inverted btn-create', title: "New snippet" do
|
= link_to new_namespace_project_snippet_path(@project.namespace, @project), class: 'btn btn-grouped btn-inverted btn-create', title: "New snippet" do
|
||||||
New snippet
|
New snippet
|
||||||
- if @snippet.submittable_as_spam? && current_user.admin?
|
- if @snippet.submittable_as_spam_by?(current_user)
|
||||||
= link_to 'Submit as spam', mark_as_spam_namespace_project_snippet_path(@project.namespace, @project, @snippet), method: :post, class: 'btn btn-grouped btn-spam', title: 'Submit as spam'
|
= link_to 'Submit as spam', mark_as_spam_namespace_project_snippet_path(@project.namespace, @project, @snippet), method: :post, class: 'btn btn-grouped btn-spam', title: 'Submit as spam'
|
||||||
- if can?(current_user, :create_project_snippet, @project) || can?(current_user, :update_project_snippet, @snippet)
|
- if can?(current_user, :create_project_snippet, @project) || can?(current_user, :update_project_snippet, @snippet)
|
||||||
.visible-xs-block.dropdown
|
.visible-xs-block.dropdown
|
||||||
|
@ -31,6 +31,6 @@
|
||||||
%li
|
%li
|
||||||
= link_to edit_namespace_project_snippet_path(@project.namespace, @project, @snippet) do
|
= link_to edit_namespace_project_snippet_path(@project.namespace, @project, @snippet) do
|
||||||
Edit
|
Edit
|
||||||
- if @snippet.submittable_as_spam? && current_user.admin?
|
- if @snippet.submittable_as_spam_by?(current_user)
|
||||||
%li
|
%li
|
||||||
= link_to 'Submit as spam', mark_as_spam_namespace_project_snippet_path(@project.namespace, @project, @snippet), method: :post
|
= link_to 'Submit as spam', mark_as_spam_namespace_project_snippet_path(@project.namespace, @project, @snippet), method: :post
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
Delete
|
Delete
|
||||||
= link_to new_snippet_path, class: "btn btn-grouped btn-inverted btn-create", title: "New snippet" do
|
= link_to new_snippet_path, class: "btn btn-grouped btn-inverted btn-create", title: "New snippet" do
|
||||||
New snippet
|
New snippet
|
||||||
- if @snippet.submittable_as_spam? && current_user.admin?
|
- if @snippet.submittable_as_spam_by?(current_user)
|
||||||
= link_to 'Submit as spam', mark_as_spam_snippet_path(@snippet), method: :post, class: 'btn btn-grouped btn-spam', title: 'Submit as spam'
|
= link_to 'Submit as spam', mark_as_spam_snippet_path(@snippet), method: :post, class: 'btn btn-grouped btn-spam', title: 'Submit as spam'
|
||||||
.visible-xs-block.dropdown
|
.visible-xs-block.dropdown
|
||||||
%button.btn.btn-default.btn-block.append-bottom-0.prepend-top-5{ data: { toggle: "dropdown" } }
|
%button.btn.btn-default.btn-block.append-bottom-0.prepend-top-5{ data: { toggle: "dropdown" } }
|
||||||
|
@ -28,6 +28,6 @@
|
||||||
%li
|
%li
|
||||||
= link_to edit_snippet_path(@snippet) do
|
= link_to edit_snippet_path(@snippet) do
|
||||||
Edit
|
Edit
|
||||||
- if @snippet.submittable_as_spam? && current_user.admin?
|
- if @snippet.submittable_as_spam_by?(current_user)
|
||||||
%li
|
%li
|
||||||
= link_to 'Submit as spam', mark_as_spam_snippet_path(@snippet), method: :post
|
= link_to 'Submit as spam', mark_as_spam_snippet_path(@snippet), method: :post
|
||||||
|
|
14
db/migrate/20170210103609_add_index_to_user_agent_detail.rb
Normal file
14
db/migrate/20170210103609_add_index_to_user_agent_detail.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
|
||||||
|
# for more information on how to write migrations for GitLab.
|
||||||
|
|
||||||
|
class AddIndexToUserAgentDetail < ActiveRecord::Migration
|
||||||
|
include Gitlab::Database::MigrationHelpers
|
||||||
|
|
||||||
|
DOWNTIME = false
|
||||||
|
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def change
|
||||||
|
add_concurrent_index(:user_agent_details, [:subject_id, :subject_type])
|
||||||
|
end
|
||||||
|
end
|
|
@ -1218,6 +1218,8 @@ ActiveRecord::Schema.define(version: 20170215200045) do
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "user_agent_details", ["subject_id", "subject_type"], name: "index_user_agent_details_on_subject_id_and_subject_type", using: :btree
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
t.string "encrypted_password", default: "", null: false
|
t.string "encrypted_password", default: "", null: false
|
||||||
|
|
|
@ -14,8 +14,9 @@ describe Issue, 'Spammable' do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'InstanceMethods' do
|
describe 'InstanceMethods' do
|
||||||
|
let(:issue) { build(:issue, spam: true) }
|
||||||
|
|
||||||
it 'should be invalid if spam' do
|
it 'should be invalid if spam' do
|
||||||
issue = build(:issue, spam: true)
|
|
||||||
expect(issue.valid?).to be_falsey
|
expect(issue.valid?).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,5 +30,20 @@ describe Issue, 'Spammable' do
|
||||||
expect(issue.check_for_spam?).to eq(false)
|
expect(issue.check_for_spam?).to eq(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#submittable_as_spam_by?' do
|
||||||
|
let(:admin) { build(:admin) }
|
||||||
|
let(:user) { build(:user) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(issue).to receive(:submittable_as_spam?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'tests if the user can submit spam' do
|
||||||
|
expect(issue.submittable_as_spam_by?(admin)).to be(true)
|
||||||
|
expect(issue.submittable_as_spam_by?(user)).to be(false)
|
||||||
|
expect(issue.submittable_as_spam_by?(nil)).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue