diff options
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | app/finders/notes_finder.rb | 11 | ||||
-rw-r--r-- | app/models/note.rb | 2 | ||||
-rw-r--r-- | db/migrate/20150206181414_add_index_to_created_at.rb | 16 | ||||
-rw-r--r-- | db/schema.rb | 14 |
5 files changed, 36 insertions, 9 deletions
diff --git a/CHANGELOG b/CHANGELOG index 7e35469f85f..ad2a703f3ca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,7 +10,7 @@ v 7.8.0 - Add diff syntax highlighting in email-on-push service notifications (Hannes Rosenögger) - Add API endpoint to fetch all changes on a MergeRequest (Jeroen van Baarsen) - View note image attachments in new tab when clicked instead of downloading them - - + - Improve sorting logic in UI and API. Explicitly define what sorting method used by default - Allow more variations for commit messages closing issues (Julien Bianchi and Hannes Rosenögger) - - diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index e2bd0a2560e..ab252821b52 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -10,19 +10,18 @@ class NotesFinder notes = case target_type when "commit" - project.notes.for_commit_id(target_id).not_inline.fresh + project.notes.for_commit_id(target_id).not_inline when "issue" - project.issues.find(target_id).notes.inc_author.fresh + project.issues.find(target_id).notes.inc_author when "merge_request" - project.merge_requests.find(target_id).mr_and_commit_notes.inc_author.fresh + project.merge_requests.find(target_id).mr_and_commit_notes.inc_author when "snippet", "project_snippet" - project.snippets.find(target_id).notes.fresh + project.snippets.find(target_id).notes else raise 'invalid target_type' end # Use overlapping intervals to avoid worrying about race conditions - notes.where('updated_at > ?', last_fetched_at - FETCH_OVERLAP). - order(created_at: :asc, id: :asc) + notes.where('updated_at > ?', last_fetched_at - FETCH_OVERLAP).fresh end end diff --git a/app/models/note.rb b/app/models/note.rb index 0b988cc3e0f..39fe421fd7a 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -49,7 +49,7 @@ class Note < ActiveRecord::Base scope :not_inline, ->{ where(line_code: [nil, '']) } scope :system, ->{ where(system: true) } scope :common, ->{ where(noteable_type: ["", nil]) } - scope :fresh, ->{ order("created_at ASC, id ASC") } + scope :fresh, ->{ order(created_at: :asc, id: :asc) } scope :inc_author_project, ->{ includes(:project, :author) } scope :inc_author, ->{ includes(:author) } diff --git a/db/migrate/20150206181414_add_index_to_created_at.rb b/db/migrate/20150206181414_add_index_to_created_at.rb new file mode 100644 index 00000000000..fc624fca60d --- /dev/null +++ b/db/migrate/20150206181414_add_index_to_created_at.rb @@ -0,0 +1,16 @@ +class AddIndexToCreatedAt < ActiveRecord::Migration + def change + add_index "users", [:created_at, :id] + add_index "members", [:created_at, :id] + add_index "projects", [:created_at, :id] + add_index "issues", [:created_at, :id] + add_index "merge_requests", [:created_at, :id] + add_index "milestones", [:created_at, :id] + add_index "namespaces", [:created_at, :id] + add_index "notes", [:created_at, :id] + add_index "identities", [:created_at, :id] + add_index "keys", [:created_at, :id] + add_index "web_hooks", [:created_at, :id] + add_index "snippets", [:created_at, :id] + end +end diff --git a/db/schema.rb b/db/schema.rb index 88a70182d45..f8c42f1871a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150205211843) do +ActiveRecord::Schema.define(version: 20150206181414) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -94,6 +94,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do t.datetime "updated_at" end + add_index "identities", ["created_at", "id"], name: "index_identities_on_created_at_and_id", using: :btree add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree create_table "issues", force: true do |t| @@ -113,6 +114,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree add_index "issues", ["author_id"], name: "index_issues_on_author_id", using: :btree + add_index "issues", ["created_at", "id"], name: "index_issues_on_created_at_and_id", using: :btree add_index "issues", ["created_at"], name: "index_issues_on_created_at", using: :btree add_index "issues", ["milestone_id"], name: "index_issues_on_milestone_id", using: :btree add_index "issues", ["project_id", "iid"], name: "index_issues_on_project_id_and_iid", unique: true, using: :btree @@ -129,6 +131,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do t.string "fingerprint" end + add_index "keys", ["created_at", "id"], name: "index_keys_on_created_at_and_id", using: :btree add_index "keys", ["user_id"], name: "index_keys_on_user_id", using: :btree create_table "label_links", force: true do |t| @@ -164,6 +167,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do end add_index "members", ["access_level"], name: "index_members_on_access_level", using: :btree + add_index "members", ["created_at", "id"], name: "index_members_on_created_at_and_id", using: :btree add_index "members", ["source_id", "source_type"], name: "index_members_on_source_id_and_source_type", using: :btree add_index "members", ["type"], name: "index_members_on_type", using: :btree add_index "members", ["user_id"], name: "index_members_on_user_id", using: :btree @@ -200,6 +204,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree add_index "merge_requests", ["author_id"], name: "index_merge_requests_on_author_id", using: :btree + add_index "merge_requests", ["created_at", "id"], name: "index_merge_requests_on_created_at_and_id", using: :btree add_index "merge_requests", ["created_at"], name: "index_merge_requests_on_created_at", using: :btree add_index "merge_requests", ["milestone_id"], name: "index_merge_requests_on_milestone_id", using: :btree add_index "merge_requests", ["source_branch"], name: "index_merge_requests_on_source_branch", using: :btree @@ -219,6 +224,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do t.integer "iid" end + add_index "milestones", ["created_at", "id"], name: "index_milestones_on_created_at_and_id", using: :btree add_index "milestones", ["due_date"], name: "index_milestones_on_due_date", using: :btree add_index "milestones", ["project_id", "iid"], name: "index_milestones_on_project_id_and_iid", unique: true, using: :btree add_index "milestones", ["project_id"], name: "index_milestones_on_project_id", using: :btree @@ -234,6 +240,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do t.string "avatar" end + add_index "namespaces", ["created_at", "id"], name: "index_namespaces_on_created_at_and_id", using: :btree add_index "namespaces", ["name"], name: "index_namespaces_on_name", using: :btree add_index "namespaces", ["owner_id"], name: "index_namespaces_on_owner_id", using: :btree add_index "namespaces", ["path"], name: "index_namespaces_on_path", using: :btree @@ -256,6 +263,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do add_index "notes", ["author_id"], name: "index_notes_on_author_id", using: :btree add_index "notes", ["commit_id"], name: "index_notes_on_commit_id", using: :btree + add_index "notes", ["created_at", "id"], name: "index_notes_on_created_at_and_id", using: :btree add_index "notes", ["created_at"], name: "index_notes_on_created_at", using: :btree add_index "notes", ["noteable_id", "noteable_type"], name: "index_notes_on_noteable_id_and_noteable_type", using: :btree add_index "notes", ["noteable_type"], name: "index_notes_on_noteable_type", using: :btree @@ -333,6 +341,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do t.string "avatar" end + add_index "projects", ["created_at", "id"], name: "index_projects_on_created_at_and_id", using: :btree add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree add_index "projects", ["last_activity_at"], name: "index_projects_on_last_activity_at", using: :btree add_index "projects", ["namespace_id"], name: "index_projects_on_namespace_id", using: :btree @@ -374,6 +383,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do end add_index "snippets", ["author_id"], name: "index_snippets_on_author_id", using: :btree + add_index "snippets", ["created_at", "id"], name: "index_snippets_on_created_at_and_id", using: :btree add_index "snippets", ["created_at"], name: "index_snippets_on_created_at", using: :btree add_index "snippets", ["expires_at"], name: "index_snippets_on_expires_at", using: :btree add_index "snippets", ["project_id"], name: "index_snippets_on_project_id", using: :btree @@ -443,6 +453,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do add_index "users", ["admin"], name: "index_users_on_admin", using: :btree add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree + add_index "users", ["created_at", "id"], name: "index_users_on_created_at_and_id", using: :btree add_index "users", ["current_sign_in_at"], name: "index_users_on_current_sign_in_at", using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["name"], name: "index_users_on_name", using: :btree @@ -473,6 +484,7 @@ ActiveRecord::Schema.define(version: 20150205211843) do t.boolean "tag_push_events", default: false end + add_index "web_hooks", ["created_at", "id"], name: "index_web_hooks_on_created_at_and_id", using: :btree add_index "web_hooks", ["project_id"], name: "index_web_hooks_on_project_id", using: :btree end |