Faster file+folder count
This commit is contained in:
parent
fd3f184a75
commit
e28f0f7468
@ -230,25 +230,6 @@ class DmsfFolder < ActiveRecord::Base
|
||||
options
|
||||
end
|
||||
|
||||
def deep_file_count
|
||||
file_count = dmsf_files.visible.all.size
|
||||
dmsf_folders.visible.each { |subfolder| file_count += subfolder.deep_file_count }
|
||||
file_count + file_links.visible.all.size + url_links.visible.all.size
|
||||
end
|
||||
|
||||
def deep_folder_count
|
||||
folder_count = dmsf_folders.visible.all.size
|
||||
dmsf_folders.visible.each { |subfolder| folder_count += subfolder.deep_folder_count }
|
||||
folder_count + folder_links.visible.all.size
|
||||
end
|
||||
|
||||
def deep_size
|
||||
size = 0
|
||||
dmsf_files.visible.each {|file| size += file.size}
|
||||
dmsf_folders.visible.each {|subfolder| size += subfolder.deep_size}
|
||||
size
|
||||
end
|
||||
|
||||
# Returns an array of projects that current user can copy folder to
|
||||
def self.allowed_target_projects_on_copy
|
||||
projects = []
|
||||
|
||||
@ -76,12 +76,10 @@ module RedmineDmsf
|
||||
end
|
||||
|
||||
def dmsf_count
|
||||
file_count = self.dmsf_files.visible.count + self.file_links.visible.count
|
||||
folder_count = self.dmsf_folders.visible.count + self.folder_links.visible.count
|
||||
self.dmsf_folders.visible.each do |f|
|
||||
file_count += f.deep_file_count
|
||||
folder_count += f.deep_folder_count
|
||||
end
|
||||
file_count = DmsfFiles.where(project_id: id).all.size +
|
||||
DmsfLinks.where(project_id: id, target_type: %(DmsfFile DmsfUrl)).all.size
|
||||
folder_count = DmsfFolders.where(project_id: id).all.size +
|
||||
DmsfLinks.where(project_id: id, target_type: 'DmsfFolder').all.size
|
||||
{ :files => file_count, :folders => folder_count }
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user