summaryrefslogtreecommitdiff
path: root/app/models/lfs_object.rb
diff options
context:
space:
mode:
authorFrank Groeneveld <frank@ivaldi.nl>2016-10-28 19:39:20 +0200
committerFrank Groeneveld <frank@ivaldi.nl>2016-10-28 19:39:20 +0200
commit17a97ef2fa3ee3aba31b401001a1f0f9744fbf12 (patch)
treeb2774acf3d91f6c74c675c23a88c46524fca974b /app/models/lfs_object.rb
parent4fd015183cdb280083384c69261c2ab5d475a54b (diff)
downloadgitlab-ce-17a97ef2fa3ee3aba31b401001a1f0f9744fbf12.tar.gz
Remove unreferenced LFS objects from DB and fs
Diffstat (limited to 'app/models/lfs_object.rb')
-rw-r--r--app/models/lfs_object.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/app/models/lfs_object.rb b/app/models/lfs_object.rb
index 18657c3e1c8..7712d5783e0 100644
--- a/app/models/lfs_object.rb
+++ b/app/models/lfs_object.rb
@@ -17,4 +17,10 @@ class LfsObject < ActiveRecord::Base
def project_allowed_access?(project)
projects.exists?(storage_project(project).id)
end
+
+ def self.destroy_unreferenced
+ joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id")
+ .where(lfs_objects_projects: { id: nil })
+ .destroy_all
+ end
end