Description:
fixed timing stat bug when used with single user mode
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r245:4658efe40e96 - - 2 files changed: 7 inserted, 1 deleted
@@ -1,37 +1,36 | |||
|
1 | 1 | class LoginController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | def index |
|
4 | 4 | # show login screen |
|
5 | 5 | reset_session |
|
6 | 6 | redirect_to :controller => 'main', :action => 'login' |
|
7 | 7 | end |
|
8 | 8 | |
|
9 | 9 | def login |
|
10 | 10 | if user = User.authenticate(params[:login], params[:password]) |
|
11 | 11 | session[:user_id] = user.id |
|
12 | 12 | session[:admin] = user.admin? |
|
13 | - UserContestStat.update_user_start_time(user) | |
|
14 | 13 | redirect_to :controller => 'main', :action => 'list' |
|
15 | 14 | else |
|
16 | 15 | flash[:notice] = 'Wrong password' |
|
17 | 16 | redirect_to :controller => 'main', :action => 'login' |
|
18 | 17 | end |
|
19 | 18 | end |
|
20 | 19 | |
|
21 | 20 | def site_login |
|
22 | 21 | begin |
|
23 | 22 | site = Site.find(params[:login][:site_id]) |
|
24 | 23 | rescue ActiveRecord::RecordNotFound |
|
25 | 24 | site = nil |
|
26 | 25 | end |
|
27 | 26 | if site==nil |
|
28 | 27 | flash[:notice] = 'Wrong site' |
|
29 | 28 | redirect_to :controller => 'main', :action => 'login' and return |
|
30 | 29 | end |
|
31 | 30 | if (site.password) and (site.password == params[:login][:password]) |
|
32 | 31 | session[:site_id] = site.id |
|
33 | 32 | redirect_to :controller => 'site', :action => 'index' |
|
34 | 33 | else |
|
35 | 34 | flash[:notice] = 'Wrong site password' |
|
36 | 35 | redirect_to :controller => 'site', :action => 'login' |
|
37 | 36 | end |
@@ -1,29 +1,31 | |||
|
1 | 1 | class MainController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :except => [:index, :login] |
|
4 | 4 | before_filter :check_viewability, :except => [:index, :login] |
|
5 | 5 | |
|
6 | + append_before_filter :update_user_start_time, :except => [:index, :login] | |
|
7 | + | |
|
6 | 8 | # COMMENTED OUT: filter in each action instead |
|
7 | 9 | # before_filter :verify_time_limit, :only => [:submit] |
|
8 | 10 | |
|
9 | 11 | verify :method => :post, :only => [:submit, :download_input, :submit_solution], |
|
10 | 12 | :redirect_to => { :action => :index } |
|
11 | 13 | |
|
12 | 14 | # COMMENT OUT: only need when having high load |
|
13 | 15 | # caches_action :index, :login |
|
14 | 16 | |
|
15 | 17 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
16 | 18 | # assigned action login as a default action. |
|
17 | 19 | def index |
|
18 | 20 | redirect_to :action => 'login' |
|
19 | 21 | end |
|
20 | 22 | |
|
21 | 23 | def login |
|
22 | 24 | saved_notice = flash[:notice] |
|
23 | 25 | reset_session |
|
24 | 26 | flash.now[:notice] = saved_notice |
|
25 | 27 | |
|
26 | 28 | # EXPERIMENT: |
|
27 | 29 | # Hide login if in single user mode and the url does not |
|
28 | 30 | # explicitly specify /login |
|
29 | 31 | # |
@@ -434,26 +436,31 | |||
|
434 | 436 | # extract running time |
|
435 | 437 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
436 | 438 | seconds = (res[1].to_f + res[2].to_f) |
|
437 | 439 | time_stat = "Time used: #{seconds} sec." |
|
438 | 440 | else |
|
439 | 441 | seconds = nil |
|
440 | 442 | time_stat = "Time used: n/a sec." |
|
441 | 443 | end |
|
442 | 444 | |
|
443 | 445 | # extract memory usage |
|
444 | 446 | if res = /s(.*)m/.match(running_stat_line) |
|
445 | 447 | memory_used = res[1].to_i |
|
446 | 448 | else |
|
447 | 449 | memory_used = -1 |
|
448 | 450 | end |
|
449 | 451 | |
|
450 | 452 | return { |
|
451 | 453 | :msg => "#{run_stat}\n#{time_stat}", |
|
452 | 454 | :running_time => seconds, |
|
453 | 455 | :exit_status => run_stat, |
|
454 | 456 | :memory_usage => memory_used |
|
455 | 457 | } |
|
456 | 458 | end |
|
457 | 459 | |
|
460 | + def update_user_start_time | |
|
461 | + user = User.find(session[:user_id]) | |
|
462 | + UserContestStat.update_user_start_time(user) | |
|
458 | 463 | end |
|
459 | 464 | |
|
465 | + end | |
|
466 | + |
You need to be logged in to leave comments.
Login now