From 9a0b7650c7626f5ce01ed04dec519a6ee624e66d Mon Sep 17 00:00:00 2001 From: TIOJ Date: Mon, 14 Sep 2015 23:21:55 +0800 Subject: [PATCH 01/15] some updates --- app/admin/admin_user.rb | 3 ++- app/views/submissions/_compiler_chooser.html.erb | 6 +++--- config/routes.rb | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/admin/admin_user.rb b/app/admin/admin_user.rb index 433be5d7..544014e6 100644 --- a/app/admin/admin_user.rb +++ b/app/admin/admin_user.rb @@ -1,5 +1,5 @@ ActiveAdmin.register AdminUser do - permit_params :email, :password, :password_confirmation + permit_params :username, :email, :password, :password_confirmation index do selectable_column @@ -18,6 +18,7 @@ form do |f| f.inputs "Admin Details" do + f.input :username f.input :email f.input :password f.input :password_confirmation diff --git a/app/views/submissions/_compiler_chooser.html.erb b/app/views/submissions/_compiler_chooser.html.erb index b51f4c95..d8cb53bd 100644 --- a/app/views/submissions/_compiler_chooser.html.erb +++ b/app/views/submissions/_compiler_chooser.html.erb @@ -1,7 +1,7 @@ <%= f.label :compiler %> <%= f.select :compiler, [ -["c++11/gnu c++ compiler 4.8.2 | options: -O2 -std=c++11", "c++11"], -["c++/gnu c++ compiler 4.8.2 | options: -O2", "c++"], -["c/gnu c compiler 4.8.2 | options: -O2 -ansi -lm", "c"], +["c++11/gnu c++ compiler 4.8.4 | options: -O2 -std=c++11", "c++11"], +["c++/gnu c++ compiler 4.8.4 | options: -O2", "c++"], +["c/gnu c compiler 4.8.4 | options: -O2 -ansi -lm", "c"], ["haskell/glasgow haskell compiler 7.8.3 with haskell platform | options: -O", "haskell"] ] , {}, {:class => 'form-control flat'} %> diff --git a/config/routes.rb b/config/routes.rb index 0996e85e..df5674ed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,6 +48,8 @@ get 'edit_announcement' => 'welcome#edit_announcement', as: :edit_announcement post 'alter_announcement' => 'welcome#alter_announcement', as: :alter_announcement get 'about' => 'about#index', as: :about + + get 'problems/:id/*file' => redirect{ |path, req| "/#{path[:file]}"}, :format => false, :id => /[0-9]+/ get 'problems/*file' => redirect{ |path, req| "/#{path[:file]}"}, :format => false # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". From 044797ab989332e77a43e37b75280acae7369591 Mon Sep 17 00:00:00 2001 From: briansu Date: Wed, 20 Dec 2017 20:03:15 +0800 Subject: [PATCH 02/15] Use raw SQL to calculate rankings --- .gitignore | 3 +++ Gemfile.lock | 5 ++++- app/controllers/users_controller.rb | 3 ++- app/controllers/welcome_controller.rb | 2 +- app/helpers/users_helper.rb | 7 +++++++ app/views/users/index.html.erb | 10 +++++++--- app/views/welcome/index.html.erb | 14 +++++++++----- 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 7f2efc7f..31b01a30 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ /config/database.yml.example /config/secret.yml +# Ignore Docker stuffs +Dockerfile +docker-compose.yml diff --git a/Gemfile.lock b/Gemfile.lock index f8efdb4e..c65498f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -120,7 +120,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (4.2.1) railties (>= 3.2.16) - json (1.8.1) + json (1.8.6) jwt (0.1.11) multi_json (>= 1.5) kaminari (0.15.1) @@ -283,3 +283,6 @@ DEPENDENCIES seo_helper (~> 1.0)! therubyracer uglifier (>= 1.3.0) + +BUNDLED WITH + 1.11.2 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e87a8191..e37a45a1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,7 @@ class UsersController < ApplicationController def index - @users = User.all.sort{|a, b| (a.ac_count == b.ac_count ? b.ac_ratio <=> a.ac_ratio : b.ac_count <=> a.ac_count) } + # Array of [user_id,ac_cnt,acsub_cnt,sub_cnt,acratio] + @users = ActiveRecord::Base.connection.execute("select user_id, count(distinct case when result='AC' then problem_id end) ac, sum(result='AC') acsub, count(*) sub, sum(result='AC') / count(*) acratio from submissions where contest_id <=> NULL group by user_id union select id, 0, 0, 0, NULL from users where id not in (select distinct user_id from submissions where contest_id <=> NULL) order by ac desc, acratio desc, sub desc, user_id;").to_a @users = Kaminari.paginate_array(@users).page(params[:page]).per(25) set_page_title "Users" end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 18378f4a..63184448 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -2,7 +2,7 @@ class WelcomeController < ApplicationController def index @bulletins = Article.order("id DESC").limit(5) @contests = Contest.order("id DESC").limit(3) - @users = User.all.sort{|a, b| (a.ac_count == b.ac_count ? b.ac_ratio <=> a.ac_ratio : b.ac_count <=> a.ac_count) } + @users = ActiveRecord::Base.connection.execute("select user_id, count(distinct case when result='AC' then problem_id end) ac, sum(result='AC') acsub, count(*) sub, sum(result='AC') / count(*) acratio from submissions where contest_id <=> NULL group by user_id union select id, 0, 0, 0, NULL from users where id not in (select distinct user_id from submissions where contest_id <=> NULL) order by ac desc, acratio desc, sub desc, user_id;").to_a @users = @users.take(10) end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index f68d868b..8343504d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -9,6 +9,13 @@ def ac_ratio_by_user(user) all_page = link_to all, submissions_path(:filter_user_id => user.id) return raw ( ratio + " (" + ac_page + "/" + all_page + ")" ) end + + def ac_ratio_by_user_sub_acsub(user, all, ac) + ratio = "%.1f%%" % (100.0 * ac / all) + ac_page = link_to ac, submissions_path(:filter_user_id => user.id, :'filter_status[]' => "AC") + all_page = link_to all, submissions_path(:filter_user_id => user.id) + return raw ( ratio + " (" + ac_page + "/" + all_page + ")" ) + end def user_problem_ac(user, problem) return Submission.exists?(["contest_id is NULL AND user_id = ? AND problem_id = ? AND result = ?", user.id, problem.id, "AC"]) diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index b4141ba3..3e3cf2b8 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -24,7 +24,11 @@ - <% @users.each_with_index do |user, idx| %> + <% @users.each_with_index do |f, idx| %> + <% + id,ac,acsub,sub,acratio = f + user = User.where(id: id).first + %> <% offset = [params[:page].to_i, 1].max %><%= (offset-1) * 25 + idx + 1 %> <%= link_to image_tag(user.avatar.mini_thumb.to_s, :class => "img-rounded"), user_path(user) %> @@ -36,8 +40,8 @@ <% else %> <% end %> - <%= user.ac_count %> - <%= ac_ratio_by_user(user) %> + <%= ac %> + <%= ac_ratio_by_user_sub_acsub(user, sub, acsub) %> <%end%> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index a893387d..9c81d06d 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -61,12 +61,16 @@ <% @users.each_with_index do |f, idx| %> - + <% + id,ac,acsub,sub,acratio = f + user = User.where(id: id).first + %> + <%= idx + 1 %> - <%= link_to image_tag(f.avatar.mini_thumb.to_s, :class => "img-rounded"), {:controller => 'users', :action => :show, :id => f.id} %> - <%= link_to f.username, user_path(f) %> - <%= f.ac_count %> - <%= ac_ratio_by_user(f) %> + <%= link_to image_tag(user.avatar.mini_thumb.to_s, :class => "img-rounded"), {:controller => 'users', :action => :show, :id => id} %> + <%= link_to user.username, user_path(user) %> + <%= ac %> + <%= ac_ratio_by_user_sub_acsub(user,sub,acsub) %> <% end %> From 87ce5eb1dcf4cd20d4a3f9e3ee69729ea5e1a623 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Wed, 20 Dec 2017 12:35:29 +0000 Subject: [PATCH 03/15] Ignore announcements --- .gitignore | 3 +++ public/announcement/anno | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7f2efc7f..9badd109 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ /tempioj /sql\ dump +# Ignore announcements. +public/announcement/anno + # Ignore bundler config. /.bundle diff --git a/public/announcement/anno b/public/announcement/anno index a56af3f0..9a56a669 100644 --- a/public/announcement/anno +++ b/public/announcement/anno @@ -1 +1 @@ -{"name":"New Feature","message":"Though it is still an experimental feature, you can now submit your solutions in haskell. \u003Ca href=\"/articles/4\"\u003ERead more\u003C/a\u003E"} \ No newline at end of file +{"name":"","message":""} \ No newline at end of file From 3b0ed6574be1aa957efd309b61ad3f43ffc6ae33 Mon Sep 17 00:00:00 2001 From: briansu Date: Wed, 20 Dec 2017 21:38:24 +0800 Subject: [PATCH 04/15] Use raw SQL to calculate problem stats --- app/controllers/problems_controller.rb | 4 ++++ app/helpers/problems_helper.rb | 17 +++++++++++++---- app/views/problems/index.html.erb | 7 +++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index b5131def..c2eadd0d 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -21,6 +21,10 @@ def index if not params[:tag].blank? @problems = @problems.tagged_with(params[:tag]) end + # Array of [problem_id,user_ac,user_cnt,sub_ac,sub_cnt] + problem_stats = ActiveRecord::Base.connection.execute("select problem_id, count(distinct case when result = 'AC' then user_id end) user_ac, count(distinct user_id) user_cnt, count(case when result = 'AC' then 1 end) sub_ac, count(*) sub_cnt from submissions where contest_id <=> NULL group by problem_id union select id, 0, 0, 0, 0 from problems where id not in (select distinct problem_id from submissions where contest_id <=> NULL) order by problem_id;").to_a + @problem_stats = problem_stats.map{ |x| [x[0] , x.from(1)] }.to_h + @problems = @problems.order("problems.id ASC").page(params[:page]).per(100) set_page_title "Problems" end diff --git a/app/helpers/problems_helper.rb b/app/helpers/problems_helper.rb index 1221a10b..fc5d4e7c 100644 --- a/app/helpers/problems_helper.rb +++ b/app/helpers/problems_helper.rb @@ -6,19 +6,21 @@ def topcoder(problem) end def users_ac_ratio(problem) -# all = User.joins(:submissions).uniq.where("submissions.contest_id is NULL AND submissions.problem_id = ?", problem.id).select("submissions.result") all = problem.submissions.where("contest_id is NULL").select("MIN(result) as result").group("user_id").map{|a| a.result} -# ac = all.where("result = ?", "AC") ac = all.count{|a| a == "AC"} all = all.count -# ac = ac.count + ratio = "%.1f%%" % (100.0 * ac / all) + ranklist_page = link_to ac.to_s + "/" + all.to_s, problem_ranklist_path(problem.id) + return raw ( ratio + " (" + ranklist_page + ")" ) + end + + def users_ac_ratio_by_cnt_accnt(problem, all, ac) ratio = "%.1f%%" % (100.0 * ac / all) ranklist_page = link_to ac.to_s + "/" + all.to_s, problem_ranklist_path(problem.id) return raw ( ratio + " (" + ranklist_page + ")" ) end def submissions_ac_ratio(problem) -# all = Submission.where("contest_id is NULL AND problem_id = ?", problem.id) all = problem.submissions.where("contest_id is NULL").select("result") ac = all.where("result = ?", "AC") all = all.count @@ -29,6 +31,13 @@ def submissions_ac_ratio(problem) return raw ( ratio + " (" + ac_page + "/" + all_page + ")" ) end + def submissions_ac_ratio_by_cnt_accnt(problem, all, ac) + ratio = "%.1f%%" % (100.0 * ac / all) + ac_page = link_to ac, :controller => :submissions, :action => :index, :problem_id => problem.id, :filter_status => "AC" + all_page = link_to all, problem_submissions_path(problem.id) + return raw ( ratio + " (" + ac_page + "/" + all_page + ")" ) + end + def user_problem_status(user, problem) if user_problem_ac(user, problem) raw '' diff --git a/app/views/problems/index.html.erb b/app/views/problems/index.html.erb index 9dd7105b..114ec4fa 100644 --- a/app/views/problems/index.html.erb +++ b/app/views/problems/index.html.erb @@ -42,6 +42,9 @@ <% @problems.each do |problem| %> + <% + user_ac,user_cnt,sub_ac,sub_cnt = @problem_stats[problem.id] + %> <% if (user_signed_in? and current_user.admin?) or (problem.visible_state == 0) %> <%= user_problem_status(current_user, problem) if user_signed_in? %> @@ -58,8 +61,8 @@ <% end %> <% end %> - <%= users_ac_ratio(problem) %> - <%= submissions_ac_ratio(problem) %> + <%= users_ac_ratio_by_cnt_accnt(problem,user_cnt,user_ac) %> + <%= submissions_ac_ratio_by_cnt_accnt(problem, sub_cnt, sub_ac) %> <% if user_signed_in? && current_user.admin? %> <% if problem.visible_state == 0 %> Public From 18996b11cc0f89016f191257d68d1b8d8cfc9202 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Wed, 20 Dec 2017 15:33:19 +0000 Subject: [PATCH 05/15] Support MySQL 5.7 --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 594c688e..7c56ad53 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' gem 'rails', '4.0.2' # Use mysql2 as the database for Active Record -gem 'mysql2' +gem 'mysql2', '~> 0.3.21' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index c65498f7..b7944cc8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -156,7 +156,7 @@ GEM multi_json (1.8.4) multi_xml (0.5.5) multipart-post (2.0.0) - mysql2 (0.3.15) + mysql2 (0.3.21) nested_form (0.3.2) net-http-digest_auth (1.4) net-http-persistent (2.9.4) @@ -271,7 +271,7 @@ DEPENDENCIES mathjax-rails mechanize mini_magick - mysql2 + mysql2 (~> 0.3.21) nested_form nokogiri omniauth @@ -285,4 +285,4 @@ DEPENDENCIES uglifier (>= 1.3.0) BUNDLED WITH - 1.11.2 + 1.16.0 From b5802dde22057065cb27cd8721130aacdd48d428 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Thu, 21 Dec 2017 01:19:08 +0000 Subject: [PATCH 06/15] Use raw SQL to calculate user AC/tried status --- app/controllers/problems_controller.rb | 10 ++++++++++ app/helpers/problems_helper.rb | 24 +++++++++++++++++------- app/helpers/users_helper.rb | 9 +++++++++ app/views/problems/index.html.erb | 2 +- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index c2eadd0d..7403caae 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -25,6 +25,16 @@ def index problem_stats = ActiveRecord::Base.connection.execute("select problem_id, count(distinct case when result = 'AC' then user_id end) user_ac, count(distinct user_id) user_cnt, count(case when result = 'AC' then 1 end) sub_ac, count(*) sub_cnt from submissions where contest_id <=> NULL group by problem_id union select id, 0, 0, 0, 0 from problems where id not in (select distinct problem_id from submissions where contest_id <=> NULL) order by problem_id;").to_a @problem_stats = problem_stats.map{ |x| [x[0] , x.from(1)] }.to_h + @user_ac = Hash.new; + @user_tried = Hash.new; + if user_signed_in? + user_ac = ActiveRecord::Base.connection.execute("select problem_id, 1 from submissions where contest_id <=> NULL and result = 'AC' and user_id = %d group by problem_id;" % current_user.id); + user_tried = ActiveRecord::Base.connection.execute("select problem_id, 1 from submissions where contest_id <=> NULL and user_id = %d group by problem_id;" % current_user.id); + + @user_ac = user_ac.map{ |x| [x[0] , x.from(1)] }.to_h + @user_tried = user_tried.map{ |x| [x[0] , x.from(1)] }.to_h + end + @problems = @problems.order("problems.id ASC").page(params[:page]).per(100) set_page_title "Problems" end diff --git a/app/helpers/problems_helper.rb b/app/helpers/problems_helper.rb index fc5d4e7c..38b50a4c 100644 --- a/app/helpers/problems_helper.rb +++ b/app/helpers/problems_helper.rb @@ -4,7 +4,7 @@ def topcoder(problem) return User.find_by_id(submission.user_id) if submission return nil if submission.blank? end - + def users_ac_ratio(problem) all = problem.submissions.where("contest_id is NULL").select("MIN(result) as result").group("user_id").map{|a| a.result} ac = all.count{|a| a == "AC"} @@ -14,12 +14,6 @@ def users_ac_ratio(problem) return raw ( ratio + " (" + ranklist_page + ")" ) end - def users_ac_ratio_by_cnt_accnt(problem, all, ac) - ratio = "%.1f%%" % (100.0 * ac / all) - ranklist_page = link_to ac.to_s + "/" + all.to_s, problem_ranklist_path(problem.id) - return raw ( ratio + " (" + ranklist_page + ")" ) - end - def submissions_ac_ratio(problem) all = problem.submissions.where("contest_id is NULL").select("result") ac = all.where("result = ?", "AC") @@ -30,6 +24,12 @@ def submissions_ac_ratio(problem) all_page = link_to all, problem_submissions_path(problem.id) return raw ( ratio + " (" + ac_page + "/" + all_page + ")" ) end + + def users_ac_ratio_by_cnt_accnt(problem, all, ac) + ratio = "%.1f%%" % (100.0 * ac / all) + ranklist_page = link_to ac.to_s + "/" + all.to_s, problem_ranklist_path(problem.id) + return raw ( ratio + " (" + ranklist_page + ")" ) + end def submissions_ac_ratio_by_cnt_accnt(problem, all, ac) ratio = "%.1f%%" % (100.0 * ac / all) @@ -47,5 +47,15 @@ def user_problem_status(user, problem) raw '' end end + + def user_problem_status_by_sql(problem) + if user_problem_ac_by_sql(problem) + raw '' + elsif user_problem_tried_by_sql(problem) + raw '' + else + raw '' + end + end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 8343504d..8c445677 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -34,5 +34,14 @@ def user_problem_tried(user, problem) return true end end + + def user_problem_ac_by_sql(problem) + return @user_ac[problem.id] + end + + def user_problem_tried_by_sql(problem) + return @user_tried[problem.id] + end + end diff --git a/app/views/problems/index.html.erb b/app/views/problems/index.html.erb index 114ec4fa..5a427c9f 100644 --- a/app/views/problems/index.html.erb +++ b/app/views/problems/index.html.erb @@ -47,7 +47,7 @@ %> <% if (user_signed_in? and current_user.admin?) or (problem.visible_state == 0) %> - <%= user_problem_status(current_user, problem) if user_signed_in? %> + <%= user_problem_status_by_sql(problem) if user_signed_in? %> <%= link_to problem.id, problem_path(problem.id) %>
<%= link_to problem.name, problem_path(problem.id) %>
From e95e9ea4b84902a4f2b58de6fe9c19d5381f3ae4 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Thu, 21 Dec 2017 11:09:39 +0000 Subject: [PATCH 07/15] Improve SQL queries --- .gitignore | 3 ++- app/controllers/problems_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- app/controllers/welcome_controller.rb | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 28868b7e..fb69eafa 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ /sql\ dump # Ignore announcements. -public/announcement/anno +/public/announcement/anno # Ignore bundler config. /.bundle @@ -31,6 +31,7 @@ public/announcement/anno /public/pmisc /public/pimgs /public/pcontest +/public/STL # Ignore binaries /bin diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index 7403caae..938df5ad 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -22,7 +22,7 @@ def index @problems = @problems.tagged_with(params[:tag]) end # Array of [problem_id,user_ac,user_cnt,sub_ac,sub_cnt] - problem_stats = ActiveRecord::Base.connection.execute("select problem_id, count(distinct case when result = 'AC' then user_id end) user_ac, count(distinct user_id) user_cnt, count(case when result = 'AC' then 1 end) sub_ac, count(*) sub_cnt from submissions where contest_id <=> NULL group by problem_id union select id, 0, 0, 0, 0 from problems where id not in (select distinct problem_id from submissions where contest_id <=> NULL) order by problem_id;").to_a + problem_stats = ActiveRecord::Base.connection.execute("select p.id problem_id, count(distinct case when s.result = 'AC' then s.user_id end) user_ac, count(distinct s.user_id) user_cnt, count(case when s.result = 'AC' then 1 end) sub_ac, count(s.id) sub_cnt from problems p left join submissions s on s.problem_id = p.id and s.contest_id is NULL group by p.id order by p.id;").to_a @problem_stats = problem_stats.map{ |x| [x[0] , x.from(1)] }.to_h @user_ac = Hash.new; diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e37a45a1..912a6a38 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,7 @@ class UsersController < ApplicationController def index # Array of [user_id,ac_cnt,acsub_cnt,sub_cnt,acratio] - @users = ActiveRecord::Base.connection.execute("select user_id, count(distinct case when result='AC' then problem_id end) ac, sum(result='AC') acsub, count(*) sub, sum(result='AC') / count(*) acratio from submissions where contest_id <=> NULL group by user_id union select id, 0, 0, 0, NULL from users where id not in (select distinct user_id from submissions where contest_id <=> NULL) order by ac desc, acratio desc, sub desc, user_id;").to_a + @users = ActiveRecord::Base.connection.execute("select u.id user_id, count(distinct case when s.result='AC' then s.problem_id end) ac, ifnull(sum(s.result='AC'), 0) acsub, count(s.id) sub, sum(s.result='AC') / count(s.id) acratio from users u left join submissions s on s.user_id = u.id and s.contest_id is NULL group by u.id order by ac desc, acratio desc, sub desc, user_id asc;").to_a @users = Kaminari.paginate_array(@users).page(params[:page]).per(25) set_page_title "Users" end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 63184448..61db4e54 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -2,8 +2,8 @@ class WelcomeController < ApplicationController def index @bulletins = Article.order("id DESC").limit(5) @contests = Contest.order("id DESC").limit(3) - @users = ActiveRecord::Base.connection.execute("select user_id, count(distinct case when result='AC' then problem_id end) ac, sum(result='AC') acsub, count(*) sub, sum(result='AC') / count(*) acratio from submissions where contest_id <=> NULL group by user_id union select id, 0, 0, 0, NULL from users where id not in (select distinct user_id from submissions where contest_id <=> NULL) order by ac desc, acratio desc, sub desc, user_id;").to_a - @users = @users.take(10) + @users = ActiveRecord::Base.connection.execute("select u.id user_id, count(distinct case when s.result='AC' then s.problem_id end) ac, ifnull(sum(s.result='AC'), 0) acsub, count(s.id) sub, sum(s.result='AC') / count(s.id) acratio from users u left join submissions s on s.user_id = u.id and s.contest_id is NULL group by u.id order by ac desc, acratio desc, sub desc, user_id asc;") + @users = @users.to_a.take(10) end def edit_announcement From 75aa4616148c61c4e0406df469130597209f2c63 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Thu, 21 Dec 2017 14:18:58 +0000 Subject: [PATCH 08/15] Rewrite SQL queries in ActiveRecord --- app/controllers/application_controller.rb | 4 ++++ app/controllers/problems_controller.rb | 14 +++----------- app/controllers/users_controller.rb | 4 +--- app/controllers/welcome_controller.rb | 3 +-- app/helpers/problems_helper.rb | 16 ++++++++++------ app/helpers/users_helper.rb | 20 +++++--------------- app/views/problems/index.html.erb | 11 ++++------- app/views/users/index.html.erb | 10 +++------- app/views/welcome/index.html.erb | 14 +++++--------- 9 files changed, 36 insertions(+), 60 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dc449cfa..0190b45d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -91,4 +91,8 @@ def set_anno @anno = JSON.parse(File.read("public/announcement/anno")) end + def get_sorted_user + User.select("users.*, count(distinct case when s.result='AC' then s.problem_id end) ac, ifnull(sum(s.result='AC'), 0) acsub, count(s.id) sub, sum(s.result='AC') / count(s.id) acratio").joins("left join submissions s on s.user_id = users.id and s.contest_id is NULL").group("users.id").order('ac desc, acratio desc, sub desc, users.id').to_a + end + end diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index 938df5ad..6bdec289 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -14,25 +14,17 @@ def index redirect_to problem_path(params[:search_id]) return end - @problems = Problem.select("problems.id, name, visible_state") + @problems = Problem.select("problems.*, count(distinct case when s.result = 'AC' then s.user_id end) user_ac, count(distinct s.user_id) user_cnt, count(case when s.result = 'AC' then 1 end) sub_ac, count(s.id) sub_cnt").joins("left join submissions s on s.problem_id = problems.id and s.contest_id is NULL").group("problems.id") if not params[:search_name].blank? @problems = @problems.where("name LIKE ?", "%%%s%%"%params[:search_name]).page(params[:page]).per(100) end if not params[:tag].blank? @problems = @problems.tagged_with(params[:tag]) end - # Array of [problem_id,user_ac,user_cnt,sub_ac,sub_cnt] - problem_stats = ActiveRecord::Base.connection.execute("select p.id problem_id, count(distinct case when s.result = 'AC' then s.user_id end) user_ac, count(distinct s.user_id) user_cnt, count(case when s.result = 'AC' then 1 end) sub_ac, count(s.id) sub_cnt from problems p left join submissions s on s.problem_id = p.id and s.contest_id is NULL group by p.id order by p.id;").to_a - @problem_stats = problem_stats.map{ |x| [x[0] , x.from(1)] }.to_h - @user_ac = Hash.new; - @user_tried = Hash.new; + @user_status = Problem.none; if user_signed_in? - user_ac = ActiveRecord::Base.connection.execute("select problem_id, 1 from submissions where contest_id <=> NULL and result = 'AC' and user_id = %d group by problem_id;" % current_user.id); - user_tried = ActiveRecord::Base.connection.execute("select problem_id, 1 from submissions where contest_id <=> NULL and user_id = %d group by problem_id;" % current_user.id); - - @user_ac = user_ac.map{ |x| [x[0] , x.from(1)] }.to_h - @user_tried = user_tried.map{ |x| [x[0] , x.from(1)] }.to_h + @user_status = Problem.select("problems.id, count(s.id) cur_user_tried, ifnull(sum(s.result = 'AC'), 0) cur_user_ac").joins("left join submissions s on s.problem_id = problems.id and s.contest_id is NULL and s.user_id = %d" % current_user.id).group("problems.id").order("problems.id").page(params[:page]).per(100).to_a end @problems = @problems.order("problems.id ASC").page(params[:page]).per(100) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 912a6a38..5ad3dd0a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,8 +1,6 @@ class UsersController < ApplicationController def index - # Array of [user_id,ac_cnt,acsub_cnt,sub_cnt,acratio] - @users = ActiveRecord::Base.connection.execute("select u.id user_id, count(distinct case when s.result='AC' then s.problem_id end) ac, ifnull(sum(s.result='AC'), 0) acsub, count(s.id) sub, sum(s.result='AC') / count(s.id) acratio from users u left join submissions s on s.user_id = u.id and s.contest_id is NULL group by u.id order by ac desc, acratio desc, sub desc, user_id asc;").to_a - @users = Kaminari.paginate_array(@users).page(params[:page]).per(25) + @users = Kaminari.paginate_array(get_sorted_user).page(params[:page]).per(25) set_page_title "Users" end def show diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 61db4e54..ccee4b70 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -2,8 +2,7 @@ class WelcomeController < ApplicationController def index @bulletins = Article.order("id DESC").limit(5) @contests = Contest.order("id DESC").limit(3) - @users = ActiveRecord::Base.connection.execute("select u.id user_id, count(distinct case when s.result='AC' then s.problem_id end) ac, ifnull(sum(s.result='AC'), 0) acsub, count(s.id) sub, sum(s.result='AC') / count(s.id) acratio from users u left join submissions s on s.user_id = u.id and s.contest_id is NULL group by u.id order by ac desc, acratio desc, sub desc, user_id asc;") - @users = @users.to_a.take(10) + @users = get_sorted_user.take(10) end def edit_announcement diff --git a/app/helpers/problems_helper.rb b/app/helpers/problems_helper.rb index 38b50a4c..023163c6 100644 --- a/app/helpers/problems_helper.rb +++ b/app/helpers/problems_helper.rb @@ -25,13 +25,17 @@ def submissions_ac_ratio(problem) return raw ( ratio + " (" + ac_page + "/" + all_page + ")" ) end - def users_ac_ratio_by_cnt_accnt(problem, all, ac) + def users_ac_ratio_with_infor(problem) + all = problem.user_cnt + ac = problem.user_ac ratio = "%.1f%%" % (100.0 * ac / all) ranklist_page = link_to ac.to_s + "/" + all.to_s, problem_ranklist_path(problem.id) return raw ( ratio + " (" + ranklist_page + ")" ) end - - def submissions_ac_ratio_by_cnt_accnt(problem, all, ac) + + def submissions_ac_ratio_with_infor(problem) + all = problem.sub_cnt + ac = problem.sub_ac ratio = "%.1f%%" % (100.0 * ac / all) ac_page = link_to ac, :controller => :submissions, :action => :index, :problem_id => problem.id, :filter_status => "AC" all_page = link_to all, problem_submissions_path(problem.id) @@ -48,10 +52,10 @@ def user_problem_status(user, problem) end end - def user_problem_status_by_sql(problem) - if user_problem_ac_by_sql(problem) + def user_problem_status_by_stat(stat) + if stat.cur_user_ac > 0 raw '' - elsif user_problem_tried_by_sql(problem) + elsif stat.cur_user_tried > 0 raw '' else raw '' diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 8c445677..7a99ae79 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -10,13 +10,13 @@ def ac_ratio_by_user(user) return raw ( ratio + " (" + ac_page + "/" + all_page + ")" ) end - def ac_ratio_by_user_sub_acsub(user, all, ac) - ratio = "%.1f%%" % (100.0 * ac / all) - ac_page = link_to ac, submissions_path(:filter_user_id => user.id, :'filter_status[]' => "AC") - all_page = link_to all, submissions_path(:filter_user_id => user.id) + def ac_ratio_by_user_with_infor(user) + ratio = "%.1f%%" % (100.0 * user.acsub / user.sub) + ac_page = link_to user.acsub, submissions_path(:filter_user_id => user.id, :'filter_status[]' => "AC") + all_page = link_to user.sub, submissions_path(:filter_user_id => user.id) return raw ( ratio + " (" + ac_page + "/" + all_page + ")" ) end - + def user_problem_ac(user, problem) return Submission.exists?(["contest_id is NULL AND user_id = ? AND problem_id = ? AND result = ?", user.id, problem.id, "AC"]) if Submission.where("contest_id is NULL AND user_id = ? AND problem_id = ? AND result = ?", user.id, problem.id, "AC").count == 0 @@ -34,14 +34,4 @@ def user_problem_tried(user, problem) return true end end - - def user_problem_ac_by_sql(problem) - return @user_ac[problem.id] - end - - def user_problem_tried_by_sql(problem) - return @user_tried[problem.id] - end - - end diff --git a/app/views/problems/index.html.erb b/app/views/problems/index.html.erb index 5a427c9f..fc8577d2 100644 --- a/app/views/problems/index.html.erb +++ b/app/views/problems/index.html.erb @@ -41,13 +41,10 @@ - <% @problems.each do |problem| %> - <% - user_ac,user_cnt,sub_ac,sub_cnt = @problem_stats[problem.id] - %> + <% @problems.zip(@user_status).each do |problem, status| %> <% if (user_signed_in? and current_user.admin?) or (problem.visible_state == 0) %> - <%= user_problem_status_by_sql(problem) if user_signed_in? %> + <%= user_problem_status_by_stat(status) if user_signed_in? %> <%= link_to problem.id, problem_path(problem.id) %>
<%= link_to problem.name, problem_path(problem.id) %>
@@ -61,8 +58,8 @@ <% end %> <% end %> - <%= users_ac_ratio_by_cnt_accnt(problem,user_cnt,user_ac) %> - <%= submissions_ac_ratio_by_cnt_accnt(problem, sub_cnt, sub_ac) %> + <%= users_ac_ratio_with_infor(problem) %> + <%= submissions_ac_ratio_with_infor(problem) %> <% if user_signed_in? && current_user.admin? %> <% if problem.visible_state == 0 %> Public diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 3e3cf2b8..e03300dd 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -24,11 +24,7 @@ - <% @users.each_with_index do |f, idx| %> - <% - id,ac,acsub,sub,acratio = f - user = User.where(id: id).first - %> + <% @users.each_with_index do |user, idx| %> <% offset = [params[:page].to_i, 1].max %><%= (offset-1) * 25 + idx + 1 %> <%= link_to image_tag(user.avatar.mini_thumb.to_s, :class => "img-rounded"), user_path(user) %> @@ -40,8 +36,8 @@ <% else %> <% end %> - <%= ac %> - <%= ac_ratio_by_user_sub_acsub(user, sub, acsub) %> + <%= user.ac %> + <%= ac_ratio_by_user_with_infor(user) %> <%end%> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 9c81d06d..3bb5f4e7 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -61,16 +61,12 @@ <% @users.each_with_index do |f, idx| %> - <% - id,ac,acsub,sub,acratio = f - user = User.where(id: id).first - %> - + <%= idx + 1 %> - <%= link_to image_tag(user.avatar.mini_thumb.to_s, :class => "img-rounded"), {:controller => 'users', :action => :show, :id => id} %> - <%= link_to user.username, user_path(user) %> - <%= ac %> - <%= ac_ratio_by_user_sub_acsub(user,sub,acsub) %> + <%= link_to image_tag(f.avatar.mini_thumb.to_s, :class => "img-rounded"), {:controller => 'users', :action => :show, :id => f.id} %> + <%= link_to f.username, user_path(f) %> + <%= f.ac %> + <%= ac_ratio_by_user_with_infor(f) %> <% end %> From c744eec4501ebf4c0b76e5fcedd2dae35a12b954 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Thu, 21 Dec 2017 23:31:55 +0000 Subject: [PATCH 09/15] Fix bug about wrong problem AC/tried status when searching --- app/controllers/problems_controller.rb | 7 +------ app/helpers/problems_helper.rb | 6 +++--- app/views/problems/index.html.erb | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index 6bdec289..ec243322 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -14,7 +14,7 @@ def index redirect_to problem_path(params[:search_id]) return end - @problems = Problem.select("problems.*, count(distinct case when s.result = 'AC' then s.user_id end) user_ac, count(distinct s.user_id) user_cnt, count(case when s.result = 'AC' then 1 end) sub_ac, count(s.id) sub_cnt").joins("left join submissions s on s.problem_id = problems.id and s.contest_id is NULL").group("problems.id") + @problems = Problem.select("problems.*, count(distinct case when s.result = 'AC' then s.user_id end) user_ac, count(distinct s.user_id) user_cnt, count(case when s.result = 'AC' then 1 end) sub_ac, count(s.id) sub_cnt, bit_or(s.result = 'AC' and s.user_id = %d) cur_user_ac, bit_or(s.user_id = %d) cur_user_tried" % ([current_user ? current_user.id : 0]*2)).joins("left join submissions s on s.problem_id = problems.id and s.contest_id is NULL").group("problems.id") if not params[:search_name].blank? @problems = @problems.where("name LIKE ?", "%%%s%%"%params[:search_name]).page(params[:page]).per(100) end @@ -22,11 +22,6 @@ def index @problems = @problems.tagged_with(params[:tag]) end - @user_status = Problem.none; - if user_signed_in? - @user_status = Problem.select("problems.id, count(s.id) cur_user_tried, ifnull(sum(s.result = 'AC'), 0) cur_user_ac").joins("left join submissions s on s.problem_id = problems.id and s.contest_id is NULL and s.user_id = %d" % current_user.id).group("problems.id").order("problems.id").page(params[:page]).per(100).to_a - end - @problems = @problems.order("problems.id ASC").page(params[:page]).per(100) set_page_title "Problems" end diff --git a/app/helpers/problems_helper.rb b/app/helpers/problems_helper.rb index 023163c6..dec41357 100644 --- a/app/helpers/problems_helper.rb +++ b/app/helpers/problems_helper.rb @@ -52,10 +52,10 @@ def user_problem_status(user, problem) end end - def user_problem_status_by_stat(stat) - if stat.cur_user_ac > 0 + def user_problem_status_with_infor(problem) + if problem.cur_user_ac > 0 raw '' - elsif stat.cur_user_tried > 0 + elsif problem.cur_user_tried > 0 raw '' else raw '' diff --git a/app/views/problems/index.html.erb b/app/views/problems/index.html.erb index fc8577d2..e2f08f5f 100644 --- a/app/views/problems/index.html.erb +++ b/app/views/problems/index.html.erb @@ -41,10 +41,10 @@ - <% @problems.zip(@user_status).each do |problem, status| %> + <% @problems.each do |problem| %> <% if (user_signed_in? and current_user.admin?) or (problem.visible_state == 0) %> - <%= user_problem_status_by_stat(status) if user_signed_in? %> + <%= user_problem_status_with_infor(problem) if user_signed_in? %> <%= link_to problem.id, problem_path(problem.id) %>
<%= link_to problem.name, problem_path(problem.id) %>
From a0114c7dc5c914a2b37db692e53166a14ca81f35 Mon Sep 17 00:00:00 2001 From: Chia-sheng Chen Date: Mon, 22 Aug 2016 00:16:34 +0800 Subject: [PATCH 10/15] Add database example --- .gitignore | 1 - config/database.yml.example | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 config/database.yml.example diff --git a/.gitignore b/.gitignore index 03ee2d3b..91255e7c 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,6 @@ /public/assets /app/views/problems/._form.html.erb.swp /config/config.yml -/config/database.yml.example /config/secrets.yml diff --git a/config/database.yml.example b/config/database.yml.example new file mode 100644 index 00000000..f5f76567 --- /dev/null +++ b/config/database.yml.example @@ -0,0 +1,34 @@ +default: &default + adapter: mysql2 + encoding: utf8 + pool: 5 + username: your_mysql_username + password: your_nysql_password + socket: /var/run/mysqld/mysqld.sock + +development: + <<: *default + database: tioj_development + + +test: + <<: *default + database: tioj_test + + + # On Heroku and other platform providers, you may have a full connection URL + # available as an environment variable. For example: + # + # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" + # + # You can use this database configuration with: + # + # production: + # url: <%= ENV['DATABASE_URL'] %> + # + + production: + <<: *default + database: tioj_production + username: production_mysql_username + password: <%= ENV['MY_APP_DATABASE_PASSWORD'] %> \ No newline at end of file From 3ce497f4eec46371d6150f63b59bc4652ae71285 Mon Sep 17 00:00:00 2001 From: Chia-sheng Chen Date: Sun, 19 Nov 2017 18:23:31 +0100 Subject: [PATCH 11/15] Bump Rails to 4.2, solve dependencies --- Gemfile | 17 +-- Gemfile.lock | 379 +++++++++++++++++++++++++++++---------------------- db/schema.rb | 210 ++++++++++++++-------------- 3 files changed, 328 insertions(+), 278 deletions(-) diff --git a/Gemfile b/Gemfile index aea912d9..add2432c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,28 +1,28 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 4.0.2' +gem 'rails', '~> 4.2' # Use mysql2 as the database for Active Record -gem 'mysql2', '~> 0.3.21' +gem 'mysql2' # Use SCSS for stylesheets -gem 'sass-rails', '~> 4.0.0' +gem 'sass-rails' gem 'less' gem 'less-rails' gem 'less-rails-bootstrap' # user -gem 'devise', '~> 3.2.4' +gem 'devise' gem 'omniauth' gem 'omniauth-facebook' # Use Redcarpet to render Markdown gem 'redcarpet' # Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' +gem 'uglifier' # Use CoffeeScript for .js.coffee assets and views -gem 'coffee-rails', '~> 4.0.0' +gem 'coffee-rails' gem 'therubyracer' # use Kaminari to paginate @@ -37,7 +37,8 @@ gem 'jquery-rails' #gem 'turbolinks' #gem 'jquery-turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 1.2' +gem 'json' +gem 'jbuilder' # nested form: https://github.com/ryanb/nested_form gem "nested_form" @@ -53,7 +54,7 @@ gem "mathjax-rails" gem 'acts-as-taggable-on' # Active Admin, db admin tool: https://github.com/gregbell/active_admin -gem 'activeadmin', github: 'gregbell/active_admin' +gem 'activeadmin', github: 'activeadmin/activeadmin' group :doc do # bundle exec rake doc:rails generates the API under doc/api. diff --git a/Gemfile.lock b/Gemfile.lock index a98ed73f..c5c8153f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,35 +1,33 @@ GIT - remote: git://github.com/ctran/annotate_models.git - revision: c952306966c9bae4438e4d40351561af3d8005c0 - specs: - annotate (2.7.0) - activerecord (>= 3.2, < 6.0) - rake (>= 10.4, < 12.0) - -GIT - remote: git://github.com/gregbell/active_admin.git - revision: cc178ad0ebe1b74729eeaa59d5c7ad9b82ed7837 + remote: git://github.com/activeadmin/activeadmin.git + revision: 6b7a77c82ce4f0a576e4397f7a86a7332c128256 specs: - activeadmin (1.0.0.pre4) - arbre (~> 1.0, >= 1.0.2) - bourbon - coffee-rails + activeadmin (2.0.0.alpha) + arbre (>= 1.1.1) formtastic (~> 3.1) formtastic_i18n - inherited_resources (~> 1.6) - jquery-rails - jquery-ui-rails - kaminari (~> 0.15) - railties (>= 3.2, < 5.1) + inherited_resources (~> 1.7) + jquery-rails (>= 4.2.0) + kaminari (>= 1.0.1) + railties (>= 4.2, < 5.2) ransack (~> 1.3) - sass-rails - sprockets (< 4.1) + sass (~> 3.4) + sprockets (>= 3.0, < 4.1) + sprockets-es6 (>= 0.9.2) + +GIT + remote: git://github.com/ctran/annotate_models.git + revision: 5f37a974f3dff68f92b3495115f1399e7db5c584 + specs: + annotate (2.7.2) + activerecord (>= 3.2, < 6.0) + rake (>= 10.4, < 13.0) GIT remote: git://github.com/norman/friendly_id.git - revision: aff0564584e84ffa505e6e278b65ca3c4ee5d698 + revision: 68cbd3d258ab301270e7e2fb3b238ead38689b34 specs: - friendly_id (5.2.0.beta.1) + friendly_id (5.2.3) activerecord (>= 4.0.0) GIT @@ -41,212 +39,262 @@ GIT GEM remote: https://rubygems.org/ specs: - actionmailer (4.0.13) - actionpack (= 4.0.13) + actionmailer (4.2.10) + actionpack (= 4.2.10) + actionview (= 4.2.10) + activejob (= 4.2.10) mail (~> 2.5, >= 2.5.4) - actionpack (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.10) + actionview (= 4.2.10) + activesupport (= 4.2.10) + rack (~> 1.6) rack-test (~> 0.6.2) - activemodel (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - activerecord (4.0.13) - activemodel (= 4.0.13) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.13) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) - activesupport (4.0.13) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - acts-as-taggable-on (4.0.0) - activerecord (>= 4.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.10) + activesupport (= 4.2.10) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (4.2.10) + activesupport (= 4.2.10) + globalid (>= 0.3.0) + activemodel (4.2.10) + activesupport (= 4.2.10) + builder (~> 3.1) + activerecord (4.2.10) + activemodel (= 4.2.10) + activesupport (= 4.2.10) + arel (~> 6.0) + activesupport (4.2.10) + i18n (~> 0.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + acts-as-taggable-on (5.0.0) + activerecord (>= 4.2.8) arbre (1.1.1) activesupport (>= 3.0.0) - arel (4.0.2) + arel (6.0.4) + babel-source (5.8.35) + babel-transpiler (0.7.0) + babel-source (>= 4.0, < 6) + execjs (~> 2.0) bcrypt (3.1.11) - bourbon (3.2.4) - sass (~> 3.2) - thor - builder (3.1.4) - carrierwave (0.11.2) - activemodel (>= 3.2.0) - activesupport (>= 3.2.0) - json (>= 1.7) + builder (3.2.3) + carrierwave (1.2.1) + activemodel (>= 4.0.0) + activesupport (>= 4.0.0) mime-types (>= 1.16) - mimemagic (>= 0.3.0) - coffee-rails (4.0.1) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) + coffee-script-source (1.12.2) commonjs (0.2.7) - devise (3.2.4) + concurrent-ruby (1.0.5) + crass (1.0.3) + devise (4.3.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 3.2.6, < 5) - thread_safe (~> 0.1) + railties (>= 4.1.0, < 5.2) + responders warden (~> 1.2.3) - domain_name (0.5.20160615) + domain_name (0.5.20170404) unf (>= 0.0.5, < 1.0.0) erubis (2.7.0) execjs (2.7.0) - faraday (0.9.2) + faraday (0.12.2) multipart-post (>= 1.2, < 3) - formtastic (3.1.4) + ffi (1.9.18) + formtastic (3.1.5) actionpack (>= 3.2.13) formtastic_i18n (0.6.0) - has_scope (0.6.0) - actionpack (>= 3.2, < 5) - activesupport (>= 3.2, < 5) - hashie (3.4.4) - hike (1.2.3) - http-cookie (1.0.2) + globalid (0.4.1) + activesupport (>= 4.2.0) + has_scope (0.7.1) + actionpack (>= 4.1, < 5.2) + activesupport (>= 4.1, < 5.2) + hashie (3.5.6) + http-cookie (1.0.3) domain_name (~> 0.5) - i18n (0.7.0) - inherited_resources (1.6.0) - actionpack (>= 3.2, < 5) - has_scope (~> 0.6.0.rc) - railties (>= 3.2, < 5) + i18n (0.9.1) + concurrent-ruby (~> 1.0) + inherited_resources (1.7.2) + actionpack (>= 3.2, < 5.2.x) + has_scope (~> 0.6) + railties (>= 3.2, < 5.2.x) responders - jbuilder (1.5.3) - activesupport (>= 3.0.0) - multi_json (>= 1.2.0) - jquery-rails (3.1.4) - railties (>= 3.0, < 5.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jquery-ui-rails (5.0.5) - railties (>= 3.2.16) - json (1.8.6) - jwt (1.5.4) - kaminari (0.17.0) - actionpack (>= 3.0.0) - activesupport (>= 3.0.0) + json (2.1.0) + jwt (1.5.6) + kaminari (1.1.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.1.1) + kaminari-activerecord (= 1.1.1) + kaminari-core (= 1.1.1) + kaminari-actionview (1.1.1) + actionview + kaminari-core (= 1.1.1) + kaminari-activerecord (1.1.1) + activerecord + kaminari-core (= 1.1.1) + kaminari-core (1.1.1) less (2.6.0) commonjs (~> 0.2.7) - less-rails (2.7.1) + less-rails (2.8.0) actionpack (>= 4.0) less (~> 2.6.0) sprockets (> 2, < 4) tilt less-rails-bootstrap (3.3.5.0) less-rails (>= 2.6, <= 2.8) - libv8 (3.16.14.15) - mail (2.6.4) - mime-types (>= 1.16, < 4) + libv8 (3.16.14.19) + loofah (2.1.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.0) + mini_mime (>= 0.1.1) mathjax-rails (2.6.1) railties (>= 3.0) - mechanize (2.7.4) + mechanize (2.7.5) domain_name (~> 0.5, >= 0.5.1) http-cookie (~> 1.0) - mime-types (>= 1.17.2, < 3) + mime-types (>= 1.17.2) net-http-digest_auth (~> 1.1, >= 1.1.1) net-http-persistent (~> 2.5, >= 2.5.2) nokogiri (~> 1.6) ntlm-http (~> 0.1, >= 0.1.1) webrobots (>= 0.0.9, < 0.2) - mime-types (2.99.2) - mimemagic (0.3.2) - mini_magick (4.5.1) - mini_portile2 (2.1.0) - minitest (4.7.5) - multi_json (1.12.1) - multi_xml (0.5.5) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_magick (4.8.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.10.3) + multi_json (1.12.2) + multi_xml (0.6.0) multipart-post (2.0.0) - mysql2 (0.3.21) + mysql2 (0.4.10) nested_form (0.3.2) - net-http-digest_auth (1.4) + net-http-digest_auth (1.4.1) net-http-persistent (2.9.4) - nokogiri (1.6.8) - mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) ntlm-http (0.1.1) - oauth2 (1.2.0) - faraday (>= 0.8, < 0.10) + oauth2 (1.4.0) + faraday (>= 0.8, < 0.13) jwt (~> 1.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - omniauth (1.3.1) - hashie (>= 1.2, < 4) - rack (>= 1.0, < 3) + omniauth (1.7.1) + hashie (>= 3.4.6, < 3.6.0) + rack (>= 1.6.2, < 3) omniauth-facebook (4.0.0) omniauth-oauth2 (~> 1.2) omniauth-oauth2 (1.4.0) oauth2 (~> 1.0) omniauth (~> 1.2) orm_adapter (0.5.0) - pkg-config (1.1.7) polyamorous (1.3.1) activerecord (>= 3.0) - rack (1.5.5) + rack (1.6.8) rack-test (0.6.3) rack (>= 1.0) - rails (4.0.13) - actionmailer (= 4.0.13) - actionpack (= 4.0.13) - activerecord (= 4.0.13) - activesupport (= 4.0.13) + rails (4.2.10) + actionmailer (= 4.2.10) + actionpack (= 4.2.10) + actionview (= 4.2.10) + activejob (= 4.2.10) + activemodel (= 4.2.10) + activerecord (= 4.2.10) + activesupport (= 4.2.10) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.13) - sprockets-rails (~> 2.0) - railties (4.0.13) - actionpack (= 4.0.13) - activesupport (= 4.0.13) + railties (= 4.2.10) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.8) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (4.2.10) + actionpack (= 4.2.10) + activesupport (= 4.2.10) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (11.2.2) - ransack (1.8.2) + rake (12.3.0) + ransack (1.8.4) actionpack (>= 3.0) activerecord (>= 3.0) activesupport (>= 3.0) i18n polyamorous (~> 1.3) - rdoc (4.2.2) - json (~> 1.4) - redcarpet (3.3.4) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rdoc (3.9.5) + redcarpet (3.4.0) ref (2.0.0) - responders (1.1.2) - railties (>= 3.2, < 4.2) - sass (3.2.19) - sass-rails (4.0.5) - railties (>= 4.0.0, < 5.0) - sass (~> 3.2.2) - sprockets (~> 2.8, < 3.0) - sprockets-rails (~> 2.0) - sdoc (0.4.1) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) - sprockets (2.12.4) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) + sanitize (2.1.0) + nokogiri (>= 1.4.4) + sass (3.5.3) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) sprockets (>= 2.8, < 4.0) - therubyracer (0.12.2) - libv8 (~> 3.16.14.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + sdoc (0.3.11) + json (>= 1.1.3) + rdoc (~> 3) + sanitize (~> 2) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-es6 (0.9.2) + babel-source (>= 5.8.11) + babel-transpiler + sprockets (>= 3.0.0) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + therubyracer (0.12.3) + libv8 (~> 3.16.14.15) ref - thor (0.19.1) - thread_safe (0.3.5) - tilt (1.4.1) - tzinfo (0.3.51) - uglifier (3.0.2) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + tzinfo (1.2.4) + thread_safe (~> 0.1) + uglifier (3.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.7.2) - warden (1.2.6) + unf_ext (0.0.7.4) + warden (1.2.7) rack (>= 1.0) webrobots (0.1.2) @@ -258,11 +306,12 @@ DEPENDENCIES acts-as-taggable-on annotate! carrierwave - coffee-rails (~> 4.0.0) - devise (~> 3.2.4) + coffee-rails + devise friendly_id! - jbuilder (~> 1.2) + jbuilder jquery-rails + json kaminari less less-rails @@ -270,18 +319,18 @@ DEPENDENCIES mathjax-rails mechanize mini_magick - mysql2 (~> 0.3.21) + mysql2 nested_form nokogiri omniauth omniauth-facebook - rails (~> 4.0.2) + rails (~> 4.2) redcarpet - sass-rails (~> 4.0.0) + sass-rails sdoc seo_helper (~> 1.0)! therubyracer - uglifier (>= 1.3.0) + uglifier BUNDLED WITH - 1.16.0 + 1.16.0.pre.3 diff --git a/db/schema.rb b/db/schema.rb index f0c5726f..4f2575a2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,13 +13,13 @@ ActiveRecord::Schema.define(version: 20150205145649) do - create_table "active_admin_comments", force: true do |t| - t.string "namespace" - t.text "body" - t.string "resource_id", null: false - t.string "resource_type", null: false - t.integer "author_id" - t.string "author_type" + create_table "active_admin_comments", force: :cascade do |t| + t.string "namespace", limit: 255 + t.text "body", limit: 65535 + t.string "resource_id", limit: 255, null: false + t.string "resource_type", limit: 255, null: false + t.integer "author_id", limit: 4 + t.string "author_type", limit: 255 t.datetime "created_at" t.datetime "updated_at" end @@ -28,53 +28,53 @@ add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree - create_table "admin_users", force: true do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + create_table "admin_users", force: :cascade do |t| + t.string "email", limit: 255, default: "", null: false + t.string "encrypted_password", limit: 255, default: "", null: false + t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", limit: 4, default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" + t.string "current_sign_in_ip", limit: 255 + t.string "last_sign_in_ip", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.string "username" + t.string "username", limit: 255 end add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true, using: :btree add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree add_index "admin_users", ["username"], name: "index_admin_users_on_username", unique: true, using: :btree - create_table "articles", force: true do |t| - t.string "title" - t.text "content" - t.integer "author_id" + create_table "articles", force: :cascade do |t| + t.string "title", limit: 255 + t.text "content", limit: 65535 + t.integer "author_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "era" + t.integer "era", limit: 4 t.boolean "pinned" - t.integer "category" + t.integer "category", limit: 4 end add_index "articles", ["category", "pinned", "era"], name: "index_articles_on_category_and_pinned_and_era", using: :btree - create_table "attachments", force: true do |t| - t.integer "article_id" - t.string "path" + create_table "attachments", force: :cascade do |t| + t.integer "article_id", limit: 4 + t.string "path", limit: 255 t.datetime "created_at" t.datetime "updated_at" end add_index "attachments", ["article_id"], name: "index_attachments_on_article_id", using: :btree - create_table "comments", force: true do |t| - t.string "title" - t.text "content" - t.integer "user_id" - t.integer "post_id" + create_table "comments", force: :cascade do |t| + t.string "title", limit: 255 + t.text "content", limit: 65535 + t.integer "user_id", limit: 4 + t.integer "post_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end @@ -82,51 +82,51 @@ add_index "comments", ["post_id"], name: "index_comments_on_post_id", using: :btree add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree - create_table "contest_problem_joints", force: true do |t| - t.integer "contest_id" - t.integer "problem_id" + create_table "contest_problem_joints", force: :cascade do |t| + t.integer "contest_id", limit: 4 + t.integer "problem_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end add_index "contest_problem_joints", ["contest_id", "problem_id"], name: "contest_task_ix", unique: true, using: :btree - create_table "contests", force: true do |t| - t.string "title" - t.text "description" + create_table "contests", force: :cascade do |t| + t.string "title", limit: 255 + t.text "description", limit: 65535 t.datetime "start_time" t.datetime "end_time" - t.integer "contest_type" + t.integer "contest_type", limit: 4 t.datetime "created_at" t.datetime "updated_at" end add_index "contests", ["start_time", "end_time"], name: "index_contests_on_start_time_and_end_time", using: :btree - create_table "judge_servers", force: true do |t| - t.string "name" - t.string "ip" - t.string "key" + create_table "judge_servers", force: :cascade do |t| + t.string "name", limit: 255 + t.string "ip", limit: 255 + t.string "key", limit: 255 t.datetime "created_at" t.datetime "updated_at" end - create_table "limits", force: true do |t| - t.integer "time", default: 1000 - t.integer "memory", default: 65536 - t.integer "output", default: 65536 + create_table "limits", force: :cascade do |t| + t.integer "time", limit: 4, default: 1000 + t.integer "memory", limit: 4, default: 65536 + t.integer "output", limit: 4, default: 65536 t.datetime "created_at" t.datetime "updated_at" - t.integer "testdatum_id" + t.integer "testdatum_id", limit: 4 end add_index "limits", ["testdatum_id"], name: "index_limits_on_testdatum_id", using: :btree - create_table "posts", force: true do |t| - t.string "title" - t.text "content" - t.integer "user_id" - t.integer "problem_id" + create_table "posts", force: :cascade do |t| + t.string "title", limit: 255 + t.text "content", limit: 65535 + t.integer "user_id", limit: 4 + t.integer "problem_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end @@ -134,39 +134,39 @@ add_index "posts", ["updated_at"], name: "index_posts_on_updated_at", using: :btree add_index "posts", ["user_id"], name: "index_posts_on_user_id", using: :btree - create_table "problems", force: true do |t| - t.string "name" - t.text "description" - t.text "source" + create_table "problems", force: :cascade do |t| + t.string "name", limit: 255 + t.text "description", limit: 65535 + t.text "source", limit: 65535 t.datetime "created_at" t.datetime "updated_at" - t.text "input" - t.text "output" - t.text "example_input" - t.text "example_output" - t.text "hint" - t.integer "visible_state", default: 0 - t.integer "problem_type" + t.text "input", limit: 65535 + t.text "output", limit: 65535 + t.text "example_input", limit: 65535 + t.text "example_output", limit: 65535 + t.text "hint", limit: 65535 + t.integer "visible_state", limit: 4, default: 0 + t.integer "problem_type", limit: 4 t.text "sjcode", limit: 16777215 t.text "interlib", limit: 16777215 - t.integer "old_pid" + t.integer "old_pid", limit: 4 end add_index "problems", ["name"], name: "index_problems_on_name", using: :btree - create_table "submissions", force: true do |t| + create_table "submissions", force: :cascade do |t| t.text "code", limit: 16777215 - t.string "compiler", default: "" - t.string "result", default: "queued" - t.integer "score", default: 0 + t.string "compiler", limit: 255, default: "" + t.string "result", limit: 255, default: "queued" + t.integer "score", limit: 4, default: 0 t.datetime "created_at" t.datetime "updated_at" - t.integer "problem_id", default: 0 - t.integer "user_id", default: 0 - t.integer "contest_id" - t.text "_result" - t.integer "total_time" - t.integer "total_memory" + t.integer "problem_id", limit: 4, default: 0 + t.integer "user_id", limit: 4, default: 0 + t.integer "contest_id", limit: 4 + t.text "_result", limit: 65535 + t.integer "total_time", limit: 4 + t.integer "total_memory", limit: 4 end add_index "submissions", ["compiler"], name: "index_submissions_on_compiler", using: :btree @@ -176,65 +176,65 @@ add_index "submissions", ["total_time", "total_memory"], name: "submissions_sort_ix", using: :btree add_index "submissions", ["user_id"], name: "index_submissions_on_user_id", using: :btree - create_table "taggings", force: true do |t| - t.integer "tag_id" - t.integer "taggable_id" - t.string "taggable_type" - t.integer "tagger_id" - t.string "tagger_type" + create_table "taggings", force: :cascade do |t| + t.integer "tag_id", limit: 4 + t.integer "taggable_id", limit: 4 + t.string "taggable_type", limit: 255 + t.integer "tagger_id", limit: 4 + t.string "tagger_type", limit: 255 t.string "context", limit: 128 t.datetime "created_at" end add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree - create_table "tags", force: true do |t| - t.string "name" - t.integer "taggings_count", default: 0 + create_table "tags", force: :cascade do |t| + t.string "name", limit: 255 + t.integer "taggings_count", limit: 4, default: 0 end add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree - create_table "testdata", force: true do |t| - t.integer "problem_id" - t.string "test_input" - t.string "test_output" + create_table "testdata", force: :cascade do |t| + t.integer "problem_id", limit: 4 + t.string "test_input", limit: 255 + t.string "test_output", limit: 255 t.datetime "created_at" t.datetime "updated_at" end - create_table "testdata_sets", force: true do |t| - t.integer "problem_id" - t.integer "from" - t.integer "to" - t.integer "score" + create_table "testdata_sets", force: :cascade do |t| + t.integer "problem_id", limit: 4 + t.integer "from", limit: 4 + t.integer "to", limit: 4 + t.integer "score", limit: 4 t.datetime "created_at" t.datetime "updated_at" end add_index "testdata_sets", ["problem_id"], name: "index_testdata_sets_on_problem_id", using: :btree - create_table "users", force: true do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + create_table "users", force: :cascade do |t| + t.string "email", limit: 255, default: "", null: false + t.string "encrypted_password", limit: 255, default: "", null: false + t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", limit: 4, default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" + t.string "current_sign_in_ip", limit: 255 + t.string "last_sign_in_ip", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.string "nickname" - t.string "avatar" - t.boolean "admin", default: false - t.string "username" - t.string "motto" - t.string "school" - t.integer "gradyear" - t.string "name" + t.string "nickname", limit: 255 + t.string "avatar", limit: 255 + t.boolean "admin", default: false + t.string "username", limit: 255 + t.string "motto", limit: 255 + t.string "school", limit: 255 + t.integer "gradyear", limit: 4 + t.string "name", limit: 255 t.datetime "last_submit_time" end From cfea2bb4b7e9e28b099aac2532994c3428a04088 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Fri, 22 Dec 2017 06:54:02 +0000 Subject: [PATCH 12/15] Fix some errors after upgrade --- Gemfile | 6 ++++- Gemfile.lock | 15 ++++++++---- app/assets/javascripts/application.js | 11 +++++---- app/models/contest_problem_joint.rb | 2 +- app/views/submissions/index.html.erb | 2 +- ...ggable_index.acts_as_taggable_on_engine.rb | 15 ++++++++++++ ...or_tag_names.acts_as_taggable_on_engine.rb | 15 ++++++++++++ ..._on_taggings.acts_as_taggable_on_engine.rb | 23 +++++++++++++++++++ db/schema.rb | 10 +++++++- 9 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20171222041537_add_missing_taggable_index.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20171222041538_change_collation_for_tag_names.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20171222041539_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb diff --git a/Gemfile b/Gemfile index add2432c..5eca1791 100644 --- a/Gemfile +++ b/Gemfile @@ -11,8 +11,9 @@ gem 'sass-rails' gem 'less' gem 'less-rails' gem 'less-rails-bootstrap' +gem 'sprockets', '3.6.3' # user -gem 'devise' +gem 'devise', '3.5.10' gem 'omniauth' gem 'omniauth-facebook' # Use Redcarpet to render Markdown @@ -83,3 +84,6 @@ gem 'annotate', github: 'ctran/annotate_models' gem 'seo_helper', '~> 1.0', :git => 'git://github.com/techbang/seo_helper.git' gem 'nokogiri' #getting old tioj probs + +# Timezone data +gem 'tzinfo-data' diff --git a/Gemfile.lock b/Gemfile.lock index c5c8153f..c829297d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,11 +98,12 @@ GEM commonjs (0.2.7) concurrent-ruby (1.0.5) crass (1.0.3) - devise (4.3.0) + devise (3.5.10) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 5.2) + railties (>= 3.2.6, < 5) responders + thread_safe (~> 0.1) warden (~> 1.2.3) domain_name (0.5.20170404) unf (>= 0.0.5, < 1.0.0) @@ -270,7 +271,7 @@ GEM json (>= 1.1.3) rdoc (~> 3) sanitize (~> 2) - sprockets (3.7.1) + sprockets (3.6.3) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-es6 (0.9.2) @@ -289,6 +290,8 @@ GEM tilt (2.0.8) tzinfo (1.2.4) thread_safe (~> 0.1) + tzinfo-data (1.2017.3) + tzinfo (>= 1.0.0) uglifier (3.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) @@ -307,7 +310,7 @@ DEPENDENCIES annotate! carrierwave coffee-rails - devise + devise (= 3.5.10) friendly_id! jbuilder jquery-rails @@ -329,8 +332,10 @@ DEPENDENCIES sass-rails sdoc seo_helper (~> 1.0)! + sprockets (= 3.6.3) therubyracer + tzinfo-data uglifier BUNDLED WITH - 1.16.0.pre.3 + 1.16.0 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 37ad0222..30e8c993 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,18 +13,19 @@ //= require jquery //= require jquery_ujs // require twitter/bootstrap +//= require jquery.tagsinput + //= require jquery-1.8.3.min //= require jquery-ui-1.10.3.custom.min //= require jquery.ui.touch-punch.min //= require bootstrap.min -//= require bootstrap-select -//= require bootstrap-switch //= require flatui-checkbox //= require flatui-radio -//= require jquery.tagsinput //= require jquery.placeholder // require jquery.turbolinks // require turbolinks //= require_tree . -//= require jquery_nested_form -//= require_self \ No newline at end of file +//= require bootstrap-select +//= require bootstrap-switch +//= require jquery_nested_form +//= require_self diff --git a/app/models/contest_problem_joint.rb b/app/models/contest_problem_joint.rb index 0cc985d4..18b5596a 100644 --- a/app/models/contest_problem_joint.rb +++ b/app/models/contest_problem_joint.rb @@ -10,7 +10,7 @@ # class ContestProblemJoint < ActiveRecord::Base - default_scope order('id ASC') + default_scope { order('id ASC') } belongs_to :contest belongs_to :problem diff --git a/app/views/submissions/index.html.erb b/app/views/submissions/index.html.erb index 879bdd9f..6647d5f4 100644 --- a/app/views/submissions/index.html.erb +++ b/app/views/submissions/index.html.erb @@ -29,7 +29,7 @@
- diff --git a/db/migrate/20171222041537_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20171222041537_add_missing_taggable_index.acts_as_taggable_on_engine.rb new file mode 100644 index 00000000..5f465693 --- /dev/null +++ b/db/migrate/20171222041537_add_missing_taggable_index.acts_as_taggable_on_engine.rb @@ -0,0 +1,15 @@ +# This migration comes from acts_as_taggable_on_engine (originally 4) +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class AddMissingTaggableIndex < ActiveRecord::Migration[4.2]; end +else + class AddMissingTaggableIndex < ActiveRecord::Migration; end +end +AddMissingTaggableIndex.class_eval do + def self.up + add_index :taggings, [:taggable_id, :taggable_type, :context] + end + + def self.down + remove_index :taggings, [:taggable_id, :taggable_type, :context] + end +end diff --git a/db/migrate/20171222041538_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/db/migrate/20171222041538_change_collation_for_tag_names.acts_as_taggable_on_engine.rb new file mode 100644 index 00000000..f119b169 --- /dev/null +++ b/db/migrate/20171222041538_change_collation_for_tag_names.acts_as_taggable_on_engine.rb @@ -0,0 +1,15 @@ +# This migration comes from acts_as_taggable_on_engine (originally 5) +# This migration is added to circumvent issue #623 and have special characters +# work properly +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class ChangeCollationForTagNames < ActiveRecord::Migration[4.2]; end +else + class ChangeCollationForTagNames < ActiveRecord::Migration; end +end +ChangeCollationForTagNames.class_eval do + def up + if ActsAsTaggableOn::Utils.using_mysql? + execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") + end + end +end diff --git a/db/migrate/20171222041539_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20171222041539_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 00000000..94e1f2e4 --- /dev/null +++ b/db/migrate/20171222041539_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,23 @@ +# This migration comes from acts_as_taggable_on_engine (originally 6) +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end +else + class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end +end +AddMissingIndexesOnTaggings.class_eval do + def change + add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id + add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id + add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type + add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id + add_index :taggings, :context unless index_exists? :taggings, :context + + unless index_exists? :taggings, [:tagger_id, :tagger_type] + add_index :taggings, [:tagger_id, :tagger_type] + end + + unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4f2575a2..85d649e2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150205145649) do +ActiveRecord::Schema.define(version: 20171222041539) do create_table "active_admin_comments", force: :cascade do |t| t.string "namespace", limit: 255 @@ -186,7 +186,15 @@ t.datetime "created_at" end + add_index "taggings", ["context"], name: "index_taggings_on_context", using: :btree add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree + add_index "taggings", ["tag_id"], name: "index_taggings_on_tag_id", using: :btree + add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree + add_index "taggings", ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy", using: :btree + add_index "taggings", ["taggable_id"], name: "index_taggings_on_taggable_id", using: :btree + add_index "taggings", ["taggable_type"], name: "index_taggings_on_taggable_type", using: :btree + add_index "taggings", ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type", using: :btree + add_index "taggings", ["tagger_id"], name: "index_taggings_on_tagger_id", using: :btree create_table "tags", force: :cascade do |t| t.string "name", limit: 255 From b4e2d8910e1ebc97854fe09a4ce03711c4a6213a Mon Sep 17 00:00:00 2001 From: briansu Date: Fri, 22 Dec 2017 19:36:10 +0800 Subject: [PATCH 13/15] Changed inclusion order of javascript libraries The original order causes error in tag editing. --- app/assets/javascripts/application.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 30e8c993..829c9ea2 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,12 +10,13 @@ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details // about supported directives. // +//= require jquery-1.8.3.min //= require jquery +//= require_tree . //= require jquery_ujs // require twitter/bootstrap //= require jquery.tagsinput -//= require jquery-1.8.3.min //= require jquery-ui-1.10.3.custom.min //= require jquery.ui.touch-punch.min //= require bootstrap.min @@ -24,7 +25,6 @@ //= require jquery.placeholder // require jquery.turbolinks // require turbolinks -//= require_tree . //= require bootstrap-select //= require bootstrap-switch //= require jquery_nested_form From 3a910cf8dd1c64ed1962c00b421853f81a4a40ad Mon Sep 17 00:00:00 2001 From: briansu Date: Sat, 23 Dec 2017 21:31:49 +0800 Subject: [PATCH 14/15] Fixed issue of 'acts-as-taggable-on' in rails 4.2 Issue caused by known changes in rails 4.2. As suggested by https://stackoverflow.com/questions/28776612/rails-acts-as-taggable-on-removes-commas-when-editing and https://github.com/mbleigh/acts-as-taggable-on/issues/620 --- app/views/problems/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/problems/_form.html.erb b/app/views/problems/_form.html.erb index 58d603ea..6722f65f 100644 --- a/app/views/problems/_form.html.erb +++ b/app/views/problems/_form.html.erb @@ -20,7 +20,7 @@
<%= f.label :tag_list, "Tags" %> - <%= f.text_field :tag_list, :class => 'tagsinput ', :id => 'tagsinput' %> + <%= f.text_field :tag_list, value: @problem.tag_list.to_s,:class => 'tagsinput ', :id => 'tagsinput' %> From aa3f8edb34c2bb1caa1226a42b3d4a0442c44ec6 Mon Sep 17 00:00:00 2001 From: adrien1018 Date: Sat, 23 Dec 2017 15:43:25 +0000 Subject: [PATCH 15/15] Update version information in Readme --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 227eb711..71b50fbc 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ -TIOJ INFOR Online Judge +[TIOJ INFOR Online Judge](http://tioj.ck.tp.edu.tw/) == -###Remember to change secret token in production!!! +### Remember to change secret token in production!!! ## Current Development Environment Ruby: 2.3.1 -Rails: 4.0.2 - -We're planning to upgrade to rails 4.2.6 +Rails: 4.2.10