Skip to content

Commit 4845401

Browse files
committed
Merge branch 'tc-index-lfs-objects-file-store' into 'master'
Enhance performance of counting local LFS objects Closes gitlab-ee#6067 See merge request gitlab-org/gitlab-ce!22143
2 parents e10ca5e + d5f290e commit 4845401

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

app/models/lfs_object.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class LfsObject < ActiveRecord::Base
77
has_many :lfs_objects_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
88
has_many :projects, through: :lfs_objects_projects
99

10-
scope :with_files_stored_locally, -> { where(file_store: [nil, LfsObjectUploader::Store::LOCAL]) }
10+
scope :with_files_stored_locally, -> { where(file_store: LfsObjectUploader::Store::LOCAL) }
1111

1212
validates :oid, presence: true, uniqueness: true
1313

@@ -26,7 +26,7 @@ def project_allowed_access?(project)
2626
end
2727

2828
def local_store?
29-
[nil, LfsObjectUploader::Store::LOCAL].include?(self.file_store)
29+
file_store == LfsObjectUploader::Store::LOCAL
3030
end
3131

3232
# rubocop: disable DestroyAll
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Enhance performance of counting local LFS objects
3+
merge_request: 22143
4+
author:
5+
type: performance
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
class AddIndexToLfsObjectsFileStore < ActiveRecord::Migration
4+
include Gitlab::Database::MigrationHelpers
5+
6+
DOWNTIME = false
7+
8+
disable_ddl_transaction!
9+
10+
def up
11+
add_concurrent_index :lfs_objects, :file_store
12+
end
13+
14+
def down
15+
remove_concurrent_index :lfs_objects, :file_store
16+
end
17+
end

db/schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,7 @@
11671167
t.integer "file_store"
11681168
end
11691169

1170+
add_index "lfs_objects", ["file_store"], name: "index_lfs_objects_on_file_store", using: :btree
11701171
add_index "lfs_objects", ["oid"], name: "index_lfs_objects_on_oid", unique: true, using: :btree
11711172

11721173
create_table "lfs_objects_projects", force: :cascade do |t|

spec/models/lfs_object_spec.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
describe LfsObject do
44
describe '#local_store?' do
5-
it 'returns true when file_store is nil' do
6-
subject.file_store = nil
7-
8-
expect(subject.local_store?).to eq true
9-
end
10-
115
it 'returns true when file_store is equal to LfsObjectUploader::Store::LOCAL' do
126
subject.file_store = LfsObjectUploader::Store::LOCAL
137

@@ -83,19 +77,6 @@
8377
describe 'file is being stored' do
8478
let(:lfs_object) { create(:lfs_object, :with_file) }
8579

86-
context 'when object has nil store' do
87-
before do
88-
lfs_object.update_column(:file_store, nil)
89-
lfs_object.reload
90-
end
91-
92-
it 'is stored locally' do
93-
expect(lfs_object.file_store).to be(nil)
94-
expect(lfs_object.file).to be_file_storage
95-
expect(lfs_object.file.object_store).to eq(ObjectStorage::Store::LOCAL)
96-
end
97-
end
98-
9980
context 'when existing object has local store' do
10081
it 'is stored locally' do
10182
expect(lfs_object.file_store).to be(ObjectStorage::Store::LOCAL)

0 commit comments

Comments
 (0)