From adf8a7bc92d761f333d08d22dc8b1f5e358441de Mon Sep 17 00:00:00 2001
From: nieguanghui
Date: Sat, 9 Nov 2013 08:26:23 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BE=E7=A8=8B=E6=B4=BB?=
=?UTF-8?q?=E8=B7=83=E5=BA=A6=E6=8E=92=E5=BA=8F=E6=96=B9=E5=BC=8F=EF=BC=8C?=
=?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=E9=93=BE=E6=8E=A5=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/projects_controller.rb | 10 +-
app/helpers/projects_helper.rb | 6 +-
app/models/project_status.rb | 2 +-
app/views/projects/_course.html.erb | 2 +-
app/views/projects/course.html.erb | 14 --
app/views/projects/index.html.erb | 17 --
.../20130828004955_stored_status_procedure.rb | 147 +++++++++++-------
...20131021024144_add_description_to_share.rb | 2 +-
.../20131107073302_stored_course_process.rb | 56 +++++++
..._add_course_ac_para_to_project_statuses.rb | 5 +
db/schema.rb | 6 +-
11 files changed, 164 insertions(+), 103 deletions(-)
create mode 100644 db/migrate/20131108133857_add_course_ac_para_to_project_statuses.rb
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 38e23c79..72501c8c 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -130,7 +130,7 @@ class ProjectsController < ApplicationController
@offset, @limit = api_offset_and_limit({:limit => 10})
- @projects_status = ProjectStatus.visible.where("project_type <> ? or project_type is null", 1)
+ @projects_status = ProjectStatus.visible.where("project_statuses.project_type <> ? or project_statuses.project_type is null", 1)
# @projects_status = ProjectStatus.visible
# @projects_status.each do |project|
# if Project.visible.find_by_id("#{project.project_id}")
@@ -174,13 +174,13 @@ class ProjectsController < ApplicationController
when '0'
@offset ||= @project_pages.reverse_offset
unless @offset == 0
- @projects_status = @projects_status.offset(@offset).limit(@limit).all.reverse
+ @projects_status = @projects_status.joins(:project).reorder("projects.created_on").offset(@offset).limit(@limit).all.reverse
else
limit = @project_count % @limit
if limit == 0
limit = @limit
end
- @projects_status = @projects_status.offset(@offset).limit(limit).all.reverse
+ @projects_status = @projects_status.joins(:project).reorder("projects.created_on").offset(@offset).limit(@limit).all.reverse
end
@s_type = 0
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
@@ -302,13 +302,13 @@ class ProjectsController < ApplicationController
when '1'
@offset ||= @project_pages.reverse_offset
unless @offset == 0
- @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse
+ @projects_status = @projects_status.reorder('course_ac_para').offset(@offset).limit(@limit).all.reverse
else
limit = @project_count % @limit
if limit == 0
limit = @limit
end
- @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse
+ @projects_status = @projects_status.reorder('course_ac_para').offset(@offset).limit(limit).all.reverse
end
@s_type = 1
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index de7cc849..ff16d5d6 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -68,17 +68,17 @@ module ProjectsHelper
when 0
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type)))
- content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type)))
+ # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type)))
when 1
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type)))
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected")
- content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type)))
+ # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type)))
when 2
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type)))
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type)))
- content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type), :class=>"selected"), :class=>"selected")
+ # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type), :class=>"selected"), :class=>"selected")
end
content = content_tag('ul', content)
diff --git a/app/models/project_status.rb b/app/models/project_status.rb
index f6d91bfd..09200e36 100644
--- a/app/models/project_status.rb
+++ b/app/models/project_status.rb
@@ -1,6 +1,6 @@
class ProjectStatus < ActiveRecord::Base
attr_accessible :changesets_count, :watchers_count, :project_id, :project_type
- belongs_to :projects
+ belongs_to :project
belongs_to :watchers
belongs_to :changesets
validates_presence_of :project_id
diff --git a/app/views/projects/_course.html.erb b/app/views/projects/_course.html.erb
index 61471055..ccee1bc2 100644
--- a/app/views/projects/_course.html.erb
+++ b/app/views/projects/_course.html.erb
@@ -38,7 +38,7 @@
<% @project.versions.each do |version| %>
<% files_count += version.attachments.count %>
<% end %>
- <%= content_tag('span', link_to(files_count, file_project_path(@project)), :class => "info") %>
+ <%= content_tag('span', link_to(files_count, project_files_path(@project)), :class => "info") %>
<%= content_tag('span', l(:label_x_data,:count => files_count)) %>
diff --git a/app/views/projects/course.html.erb b/app/views/projects/course.html.erb
index 9ab5a42b..8c1212c4 100644
--- a/app/views/projects/course.html.erb
+++ b/app/views/projects/course.html.erb
@@ -34,20 +34,6 @@
<%= sort_course(@s_type, @project_type)%>
-
-
<%= render_project_hierarchy(@projects)%>
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index 76c6fc26..e9b780d0 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -32,23 +32,6 @@
<%= sort_project(@s_type, @project_type) %>
-
-
-
-
-
<%= render_project_hierarchy(@projects)%>
diff --git a/db/migrate/20130828004955_stored_status_procedure.rb b/db/migrate/20130828004955_stored_status_procedure.rb
index a27a6b97..94fa3d04 100644
--- a/db/migrate/20130828004955_stored_status_procedure.rb
+++ b/db/migrate/20130828004955_stored_status_procedure.rb
@@ -2,57 +2,88 @@ class StoredStatusProcedure < ActiveRecord::Migration
def up
#sql = <<- END_OF_SQL_CODE
execute "
-create procedure `sp_user_status_cursor`()
-begin
- declare user_uid bigint(22);
- declare user_changesets_count int(10);
- declare _done tinyint(1) default 0;
- declare cur_user cursor for select user_id, count(*) from changesets where user_id != '' group by user_id;
- declare continue handler for not found set _done = 1;
- open cur_user;
- loop_xxx:loop
- fetch cur_user into user_uid,user_changesets_count;
- if _done=1 then
- leave loop_xxx;
- end if;
- begin
- declare journals_for_messages_count int(10);
- declare journals_count int(10);
- declare comments_count int(10);
- declare messages_count int(10);
- declare news_count int(10);
- declare wiki_contents_count int(10);
- declare activities_count int(10);
- declare total_count numeric(8,2);
-
- select count(*) into journals_for_messages_count from journals_for_messages where user_id = user_uid;
- select count(*) into journals_count from journals where user_id = user_uid;
- select count(*) into comments_count from comments where author_id = user_uid;
- select count(*) into messages_count from messages where author_id = user_uid;
- select count(*) into news_count from news where author_id = user_uid;
- select count(*) into wiki_contents_count from wiki_contents where author_id = user_uid;
- select count(*) into activities_count from activities where user_id = user_uid;
-
- set total_count = journals_for_messages_count*0.05 +
- journals_count*0.1 +
- comments_count*0.1 +
- messages_count*0.05 +
- news_count*0.1 +
- wiki_contents_count*0.1 +
- activities_count*0.2 +
- user_changesets_count*0.3;
-
- update user_statuses set changesets_count = user_changesets_count, grade = total_count where user_id = user_uid;
- commit;
- end;
- end loop;
-end;
+CREATE PROCEDURE `sp_user_status_cursor` ()
+BEGIN
+ DECLARE user_uid bigint(22);
+ DECLARE user_changesets_count int(10);
+ DECLARE _done tinyint(1) DEFAULT 0;
+ DECLARE cur_user CURSOR FOR
+ SELECT
+ user_id,
+ COUNT(*)
+ FROM changesets
+ WHERE user_id != ''
+ GROUP BY user_id;
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1;
+ OPEN cur_user;
+loop_xxx:
+LOOP
+ FETCH cur_user INTO user_uid, user_changesets_count;
+ IF _done = 1 THEN
+ LEAVE loop_xxx;
+ END IF;
+ BEGIN
+ DECLARE journals_for_messages_count int(10);
+ DECLARE journals_count int(10);
+ DECLARE comments_count int(10);
+ DECLARE messages_count int(10);
+ DECLARE news_count int(10);
+ DECLARE wiki_contents_count int(10);
+ DECLARE activities_count int(10);
+ DECLARE total_count numeric(8, 2);
+
+ SELECT
+ COUNT(*) INTO journals_for_messages_count
+ FROM journals_for_messages
+ WHERE user_id = user_uid;
+ SELECT
+ COUNT(*) INTO journals_count
+ FROM journals
+ WHERE user_id = user_uid;
+ SELECT
+ COUNT(*) INTO comments_count
+ FROM comments
+ WHERE author_id = user_uid;
+ SELECT
+ COUNT(*) INTO messages_count
+ FROM messages
+ WHERE author_id = user_uid;
+ SELECT
+ COUNT(*) INTO news_count
+ FROM news
+ WHERE author_id = user_uid;
+ SELECT
+ COUNT(*) INTO wiki_contents_count
+ FROM wiki_contents
+ WHERE author_id = user_uid;
+ SELECT
+ COUNT(*) INTO activities_count
+ FROM activities
+ WHERE user_id = user_uid;
+
+ SET total_count = journals_for_messages_count * 0.05 +
+ journals_count * 0.1 +
+ comments_count * 0.1 +
+ messages_count * 0.05 +
+ news_count * 0.1 +
+ wiki_contents_count * 0.1 +
+ activities_count * 0.2 +
+ user_changesets_count * 0.3;
+
+ UPDATE user_statuses
+ SET changesets_count = user_changesets_count,
+ grade = total_count
+ WHERE user_id = user_uid;
+ COMMIT;
+ END;
+END LOOP;
+END;
"
execute "
- create event if not exists e_test
-on schedule every 1 day starts'2013-08-27 01:50:00'
-on completion preserve
-do call `sp_user_status_cursor`();
+ CREATE EVENT IF NOT EXISTS e_test
+ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00'
+ON COMPLETION PRESERVE
+DO CALL `sp_user_status_cursor`();
"
execute "
CREATE PROCEDURE `sp_project_status_cursor` ()
@@ -323,27 +354,27 @@ END LOOP;
END;
"
execute "
- create event if not exists e_project_status_test
-on schedule every 1 day starts'2013-08-27 01:50:00'
-on completion preserve
-do call `sp_project_status_cursor`();
+ CREATE EVENT IF NOT EXISTS e_project_status_test
+ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00'
+ON COMPLETION PRESERVE
+DO CALL `sp_project_status_cursor`();
"
execute "
- set global event_scheduler = on;
+ SET GLOBAL event_scheduler = ON;
"
end
def down
- execute " drop procedure if exists `sp_user_status_cursor`;
+ execute " DROP PROCEDURE IF EXISTS `sp_user_status_cursor`;
"
execute "
- drop event if exists e_test;
+ DROP EVENT IF EXISTS e_test;
"
execute "
- drop procedure if exists `sp_project_status_cursor`;
+ DROP PROCEDURE IF EXISTS `sp_project_status_cursor`;
"
execute "
- drop event if exists e_project_status_test;
+ DROP EVENT IF EXISTS e_project_status_test;
"
end
end
diff --git a/db/migrate/20131021024144_add_description_to_share.rb b/db/migrate/20131021024144_add_description_to_share.rb
index 1ac25a9b..52730f34 100644
--- a/db/migrate/20131021024144_add_description_to_share.rb
+++ b/db/migrate/20131021024144_add_description_to_share.rb
@@ -1,5 +1,5 @@
class AddDescriptionToShare < ActiveRecord::Migration
def change
- add_column :shares, :description, :string
+ # add_column :shares, :description, :string
end
end
diff --git a/db/migrate/20131107073302_stored_course_process.rb b/db/migrate/20131107073302_stored_course_process.rb
index e21b1829..c49376e2 100644
--- a/db/migrate/20131107073302_stored_course_process.rb
+++ b/db/migrate/20131107073302_stored_course_process.rb
@@ -1,7 +1,63 @@
class StoredCourseProcess < ActiveRecord::Migration
def up
+ execute "
+CREATE PROCEDURE sp_course_cursor ()
+BEGIN
+ DECLARE course_uid int(10);
+ DECLARE _done tinyint(1) DEFAULT 0;
+ DECLARE cur_course CURSOR FOR
+ SELECT
+ `projects`.id
+ FROM `projects`
+ WHERE projects.status <> 9 AND projects.is_public = 1 AND projects.project_type = 1;
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1;
+
+ OPEN cur_course;
+loop_course:
+LOOP
+ FETCH cur_course INTO course_uid;
+ IF _done = 1 THEN
+ LEAVE loop_course;
+ END IF;
+
+ BEGIN
+ DECLARE members_count int(4) DEFAULT 0;
+ DECLARE attachments_count int(4) DEFAULT 0;
+ DECLARE total_count int(4) DEFAULT 0;
+ SELECT
+ COUNT(*) INTO members_count
+ FROM `members` inner join `users`
+ WHERE `members`.`project_id` = course_uid AND `members`.`user_id` = `users`.`id` AND `users`.`type` = 'User' AND `users`.`status` = 1;
+ SELECT
+ COUNT(*) INTO attachments_count
+ FROM `attachments`
+ WHERE `attachments`.`container_id` = course_uid AND `attachments`.`container_type` = 'Project';
+ SET total_count = members_count + attachments_count;
+ UPDATE project_statuses
+ SET course_ac_para = total_count
+ WHERE project_statuses.project_id = course_uid;
+ COMMIT;
+
+ END;
+END LOOP;
+END;
+"
+ execute "
+ CREATE EVENT IF NOT EXISTS e_project_status_course
+ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00'
+ON COMPLETION PRESERVE
+DO CALL sp_course_cursor();
+"
+ execute "
+ SET GLOBAL event_scheduler = ON;
+"
end
def down
+ execute " DROP PROCEDURE IF EXISTS sp_course_cursor;
+ "
+ execute "
+ DROP EVENT IF EXISTS e_project_status_course;
+ "
end
end
diff --git a/db/migrate/20131108133857_add_course_ac_para_to_project_statuses.rb b/db/migrate/20131108133857_add_course_ac_para_to_project_statuses.rb
new file mode 100644
index 00000000..e4483a47
--- /dev/null
+++ b/db/migrate/20131108133857_add_course_ac_para_to_project_statuses.rb
@@ -0,0 +1,5 @@
+class AddCourseAcParaToProjectStatuses < ActiveRecord::Migration
+ def change
+ add_column :project_statuses, :course_ac_para, :integer, :default => 0;
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a5a245bd..b4f0a31b 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20131031093317) do
+ActiveRecord::Schema.define(:version => 20131108133857) do
create_table "a_user_watchers", :force => true do |t|
t.string "name"
@@ -510,11 +510,11 @@ ActiveRecord::Schema.define(:version => 20131031093317) do
t.integer "project_id"
t.integer "project_type"
t.integer "gitlab_group_id", :limit => 8
- t.float "grade"
+ t.float "grade", :default => 0.0
+ t.integer "course_ac_para", :default => 0
end
add_index "project_statuses", ["changesets_count"], :name => "index_project_statuses_on_changesets_count"
- add_index "project_statuses", ["grade"], :name => "index_project_statuses_on_grade"
add_index "project_statuses", ["watchers_count"], :name => "index_project_statuses_on_watchers_count"
create_table "project_tags", :force => true do |t|