From 343866a0158c675d47bc1d1fdfe21c97b9cd9b65 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Wed, 13 Nov 2013 09:14:42 +0100 Subject: [PATCH] The main document view seeded up 3x --- app/controllers/dmsf_controller.rb | 3 +- app/models/dmsf_file.rb | 6 +- app/models/dmsf_folder.rb | 31 ++------- app/views/dmsf/show.html.erb | 69 ++++++++++--------- ...3141401_add_index_to_dmsf_file_revision.rb | 27 ++++++++ .../20131113141402_add_index_to_dmsf_lock.rb | 27 ++++++++ 6 files changed, 102 insertions(+), 61 deletions(-) create mode 100644 db/migrate/20131113141401_add_index_to_dmsf_file_revision.rb create mode 100644 db/migrate/20131113141402_add_index_to_dmsf_lock.rb diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 60f5c64b..72877bfc 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -35,10 +35,11 @@ class DmsfController < ApplicationController def show unless @folder @subfolders = @project.dmsf_folders.visible - @files = @project.dmsf_files.visible + @files = @project.dmsf_files.visible else @subfolders = @folder.subfolders.visible @files = @folder.files.visible + @locked_for_user = @folder.locked_for_user? end @files.sort! do |a,b| diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 55bd8673..6a96ec4b 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -94,8 +94,10 @@ class DmsfFile < ActiveRecord::Base end def last_revision - return self.revisions.visible.first unless deleted - self.revisions.first + unless @last_revision + @last_revision = deleted ? self.revisions.first : self.revisions.visible.first + end + @last_revision end def delete diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index d024e186..164ef096 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -133,38 +133,19 @@ class DmsfFolder < ActiveRecord::Base end end return tree - end - + end + def deep_file_count - file_count = self.files.visible.length + file_count = self.files.visible.count self.subfolders.visible.each {|subfolder| file_count += subfolder.deep_file_count} file_count - end - - def deep_folder_count - folder_count = self.subfolders.length - self.subfolders.each {|subfolder| folder_count += subfolder.deep_folder_count} - folder_count - end - - def self.project_deep_folder_count(project) - subfolders = self.project_root_folders(project) - folder_count = subfolders.length - subfolders.each{|subfolder| folder_count += subfolder.deep_folder_count} - folder_count - end - - def self.project_deep_file_count(project) - file_count = DmsfFile.project_root_files(project).length - self.project_root_folders(project).each{|subfolder| file_count += subfolder.deep_file_count} - file_count - end + end def deep_folder_count - folder_count = self.subfolders.length + folder_count = self.subfolders.visible.count self.subfolders.visible.each {|subfolder| folder_count += subfolder.deep_folder_count} folder_count - end + end def deep_size size = 0 diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index 461bcf3d..3aacb67a 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -21,19 +21,18 @@ %> <% html_title(l(:dmsf)) %> -
<% if User.current.allowed_to?(:folder_manipulation, @project) %> <% if @folder.nil? %>   <%= link_to('', {:action => 'edit_root', :id => @project}, :title => l(:link_edit, :title => l(:link_documents)), :class => 'icon icon-edit') %> - <% elsif (@folder && !@folder.locked_for_user? ) %> + <% elsif @locked_for_user %>   <%= link_to('', {:action => 'edit', :id => @project, :folder_id => @folder }, :title => l(:link_edit, :title => h(@folder.title)), :class => 'icon icon-edit') %> <% end %> - <% if @folder && (!@folder.locked_for_user? || User.current.allowed_to?(:force_file_unlock, @project)) %> + <% if @folder && (!@locked_for_user || User.current.allowed_to?(:force_file_unlock, @project)) %> <% if @folder.locked? %> <% unless @folder.unlockable? %> <%= image_tag('locked.png', :plugin => :redmine_dmsf, :title => l(:title_folder_parent_locked, :name => @folder.folder.lock.reverse[0].folder.title)) unless @folder.nil?%> @@ -62,7 +61,7 @@ <% end %>   <%= link_to('', {:action => 'new', :id => @project, :parent_id => @folder }, - :title => l(:link_create_folder), :class => 'icon icon-add') unless (@folder && @folder.locked_for_user?) %> + :title => l(:link_create_folder), :class => 'icon icon-add') unless @locked_for_user %> <% end %>
@@ -89,7 +88,7 @@
<%= submit_tag(l(:submit_download), :title => l(:title_download_checked), :name => 'download_entries') %> <%= submit_tag(l(:submit_email), :title => l(:title_send_checked_by_email), :name => 'email_entries') %> - <% if User.current.allowed_to?(:file_manipulation, @project) && (@folder && !@folder.locked_for_user?) %> + <% if User.current.allowed_to?(:file_manipulation, @project) && @folder && !@locked_for_user %> <% end %>
@@ -110,24 +109,26 @@ - + <% @subfolders.each do |subfolder| %> + <% locked_for_user = subfolder.locked_for_user? %> + <% locked = subfolder.locked? %> <%= check_box_tag('subfolders[]', subfolder.id, false, :title => l(:title_check_for_zip_download_or_email)) %> - + <%= link_to(h(subfolder.title), - {:action => 'show', :id => @project, :folder_id => subfolder}, :class => 'icon icon-folder') %> -
[<%= subfolder.deep_file_count %>]
- - <%= number_to_human_size(subfolder.deep_size) %> - <%= format_time(subfolder.updated_at) %> - <% if subfolder.locked_for_user? %> + {:action => 'show', :id => @project, :folder_id => subfolder}, :class => 'icon icon-folder') %> +
[<%= subfolder.files.visible.count %>]
+ + + <%= format_time(subfolder.updated_at) %> + <% if locked_for_user %> <%= link_to(image_tag('locked.png', :plugin => :redmine_dmsf), {:controller => 'users', :action => 'show', :id => subfolder.lock.reverse[0].user }, :title => l(:title_locked_by_user, :user => subfolder.lock.reverse[0].user.to_s)) %> - <% elsif subfolder.locked? %> + <% elsif locked %> <%= image_tag('lockedbycurrent.png', :title => l(:title_locked_by_you), :plugin => :redmine_dmsf) %> - <% end %> + <% end %> @@ -148,15 +149,15 @@ <% end %>
<% if User.current.allowed_to?(:folder_manipulation, @project) %> -
+
<%= link_to(image_tag('edit.png', :class =>'detail_icon'), {:action => 'edit', :id => @project, :folder_id => subfolder }, - :title => l(:link_edit, :title => h(subfolder.title))) unless subfolder.locked_for_user? %> + :title => l(:link_edit, :title => h(subfolder.title))) unless locked_for_user %>
<% end %> -
- <% unless subfolder.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%> - <% if subfolder.locked? %> +
+ <% unless locked_for_user && !User.current.allowed_to?(:force_file_unlock, @project)%> + <% if locked %> <% if subfolder.unlockable? %> <%= link_to_function(image_tag('unlock.png', :plugin => :redmine_dmsf), "manipulation_link('#{url_for(:controller => 'dmsf', :action => 'unlock', @@ -171,26 +172,29 @@ "manipulation_link('#{url_for(:controller => 'dmsf', :action => 'lock', :id => @project, :folder_id => subfolder)}')", :title => l(:title_lock_file)) %> - <% end %> + <% end %>   <% end %> + <% jetzt = Time.now %> <%= link_to_function(image_tag('delete.png', :plugin => :redmine_dmsf), "confirmation_link('#{url_for(:action => 'delete', :id => @project, :folder_id => @folder, :delete_folder_id => subfolder)}', '#{l(:question_do_you_really_want_to_delete_this_entry)}')", - :title => l(:title_delete)) unless subfolder.locked_for_user? %> + :title => l(:title_delete)) unless locked_for_user %>

0 - <%= subfolder.deep_size %> + 0 - <% end %> + <% end %> <% workflows_available = DmsfWorkflow.where(['project_id = ? OR project_id IS NULL', @project.id]).count > 0 %> <% @files.each do |file| %> <% unless file.last_revision %> <% Rails.logger.error "Error: dmsf_file id #{file.id} has no revision!" %> <% next %> <% end %> + <% locked_for_user = file.locked_for_user? %> + <% locked = file.locked? %> <% wf = DmsfWorkflow.find_by_id(file.last_revision.dmsf_workflow_id) %> <%= check_box_tag('files[]', file.id, false, :title => l(:title_check_for_zip_download_or_email)) %> @@ -206,11 +210,11 @@ <%= number_to_human_size(file.last_revision.size) %> <%= format_time(file.last_revision.updated_at) %> - <% if file.locked_for_user? %> + <% if locked_for_user %> <%= link_to(image_tag('locked.png', :plugin => :redmine_dmsf), {:controller => 'users', :action => 'show', :id => file.lock.reverse[0].user }, :title => l(:title_locked_by_user, :user => file.lock.reverse[0].user.to_s)) %> - <% elsif file.locked? %> + <% elsif locked %> <%= image_tag('lockedbycurrent.png', :title => l(:title_locked_by_you), :plugin => :redmine_dmsf) %> <% end %> @@ -293,12 +297,12 @@
<%= link_to(image_tag('filedetails.png', :plugin => :redmine_dmsf, :class =>'detail_icon'), - {:controller => "dmsf_files", :action => :show, :id => file }, + {:controller => 'dmsf_files', :action => :show, :id => file }, :title => l(:link_details, :title =>h(file.last_revision.title))) %>
- <% unless file.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%> - <% if file.locked? %> + <% unless locked_for_user && !User.current.allowed_to?(:force_file_unlock, @project)%> + <% if locked %> <% if file.unlockable? %> <%= link_to_function(image_tag('unlock.png', :plugin => :redmine_dmsf), "manipulation_link('#{url_for(:controller => 'dmsf_files', :action => 'unlock', :id => file)}')", @@ -314,7 +318,7 @@ <% end %>   <% end %> - <% if User.current.allowed_to?(:file_manipulation, @project) && !file.locked_for_user? %> + <% if User.current.allowed_to?(:file_manipulation, @project) && !locked_for_user %> <%= link_to_function(image_tag('delete.png', :plugin => :redmine_dmsf), "confirmation_link('#{url_for(:controller => 'dmsf_files', :action => 'delete', :id => file)}', '#{l(:question_do_you_really_want_to_delete_this_entry)}')", :title => l(:title_delete)) %> @@ -330,7 +334,7 @@
-<% end %> +<% end %> <% end %> -<%= render(:partial => 'multi_upload') if (User.current.allowed_to?(:file_manipulation, @project) && - (@folder.nil? || (@folder && !@folder.locked_for_user?))) %> +<%= render(:partial => 'multi_upload') if (User.current.allowed_to?(:file_manipulation, @project) && !@locked_for_user) %>
diff --git a/db/migrate/20131113141401_add_index_to_dmsf_file_revision.rb b/db/migrate/20131113141401_add_index_to_dmsf_file_revision.rb new file mode 100644 index 00000000..f0746052 --- /dev/null +++ b/db/migrate/20131113141401_add_index_to_dmsf_file_revision.rb @@ -0,0 +1,27 @@ +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2013 Karel Picman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class AddIndexToDmsfFileRevision < ActiveRecord::Migration + def self.up + add_index :dmsf_file_revisions, :dmsf_file_id + end + + def self.down + remove_index :dmsf_file_revisions, :dmsf_file_id + end +end \ No newline at end of file diff --git a/db/migrate/20131113141402_add_index_to_dmsf_lock.rb b/db/migrate/20131113141402_add_index_to_dmsf_lock.rb new file mode 100644 index 00000000..9e70a488 --- /dev/null +++ b/db/migrate/20131113141402_add_index_to_dmsf_lock.rb @@ -0,0 +1,27 @@ +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2013 Karel Picman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class AddIndexToDmsfLock < ActiveRecord::Migration + def self.up + add_index :dmsf_locks, :entity_id + end + + def self.down + remove_index :dmsf_locks, :entity_id + end +end \ No newline at end of file