Skip to content

Commit 26c88cc

Browse files
committed
Merge pull request code-dot-org#836 from code-dot-org/test
DTP
2 parents cd5fcd1 + 9b6d059 commit 26c88cc

File tree

9 files changed

+43
-9
lines changed

9 files changed

+43
-9
lines changed

aws/build.rake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ $websites = build_task('websites', [deploy_dir('rebuild'), BLOCKLY_COMMIT_TASK])
158158
RakeUtils.system 'rake', 'build'
159159

160160
if rack_env?(:production) && CDO.daemon
161+
HipChat.log "Putting <b>dashboard</b> scripts in redis..."
162+
RakeUtils.rake 'seed:script_cache_to_redis'
163+
161164
thread_count = 1 + (CDO.app_servers.keys.count / 10)
162165
threaded_each CDO.app_servers.keys, thread_count do |name|
163166
upgrade_frontend name, CDO.app_servers[name]

dashboard/app/models/script.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,34 @@ def starting_level
7373
candidate_level
7474
end
7575

76-
def self.script_cache
77-
@@script_cache ||= {}.tap do |cache|
76+
def self.redis
77+
@@redis ||= CDO.level_sources_redis_url ? Redis.connect(url:CDO.level_sources_redis_url) : Hash.new
78+
end
79+
80+
def self.script_cache_from_redis
81+
if marshalled = self.redis['script-cache']
82+
Script.connection # rails doesn't load the mysql libraries unless you ask it to, this confuses Marshal
83+
Marshal.load marshalled
84+
end
85+
end
86+
87+
def self.script_cache_to_redis
88+
redis['script-cache'] = Marshal.dump(script_cache_from_db)
89+
end
90+
91+
def self.script_cache_from_db
92+
{}.tap do |cache|
7893
[twenty_hour_script, frozen_script, hoc_script, flappy_script, playlab_script].each do |script|
7994
cache[script.name] = script
8095
cache[script.id.to_s] = script
8196
end
8297
end
8398
end
8499

100+
def self.script_cache
101+
@@script_cache ||= script_cache_from_redis || script_cache_from_db
102+
end
103+
85104
def self.get_from_cache(id)
86105
if self.script_cache[id.to_s]
87106
self.script_cache[id.to_s]

dashboard/app/models/user.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,14 @@ def track_script_progress(script)
560560

561561
update = {}
562562
update[:started_at] = time_now unless user_script.started_at
563-
update[:last_progress_at] = time_now
563+
update[:last_progress_at] = time_now unless user_script.last_progress_at
564564

565565
if !user_script.completed_at && user_script.check_completed?
566566
update[:completed_at] = time_now
567567
end
568568

569569
# update_all bypasses validations/transactions/etc
570-
UserScript.where(id: user_script.id).update_all(update)
570+
UserScript.where(id: user_script.id).update_all(update) unless update.empty?
571571
end
572572
end
573573

dashboard/lib/tasks/seed.rake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,8 @@ namespace :seed do
295295

296296
task all: [:videos, :concepts, :scripts, :trophies, :prize_providers, :callouts, STANFORD_HINTS_IMPORTED, :secret_words, :secret_pictures]
297297
task incremental: [:videos, :concepts, :scripts_incremental, :trophies, :prize_providers, :callouts, STANFORD_HINTS_IMPORTED, :secret_words, :secret_pictures]
298+
299+
task script_cache_to_redis: :environment do
300+
Script.script_cache_to_redis
301+
end
298302
end

dashboard/test/controllers/activities_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def studio_program_with_text(text)
333333
assert_equal @script_level.script, user_script.script
334334
assert_equal @user, user_script.user
335335
assert_equal script_start_date.to_i, user_script.started_at.to_i
336-
assert user_script.started_at != user_script.last_progress_at
336+
# assert user_script.started_at != user_script.last_progress_at # I turned off updates
337337
assert user_script.assigned_at.nil?
338338
assert user_script.completed_at.nil?
339339
end

dashboard/test/controllers/level_sources_controller_test.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ class LevelSourcesControllerTest < ActionController::TestCase
55
@admin = create(:admin)
66
@level_source = create(:level_source)
77
@hidden_level_source = create(:level_source, hidden: true)
8-
9-
# so we actually test this
10-
CDO.disable_s3_image_uploads = false
118
end
129

1310
test "should get edit" do

dashboard/test/models/script_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,13 @@ def setup
208208
artist.get_script_level_by_stage_and_position(11, 1)
209209
end
210210
end
211+
212+
test 'gets script cache from redis (or fake redis)' do
213+
Script.script_cache_to_redis # in test this is just a hash
214+
215+
Script.connection.disconnect! # we don't need no stinkin db
216+
217+
assert_equal 'Flappy', Script.get_from_cache('flappy').script_levels[3].level.game.name
218+
assert_equal 'anna', Script.get_from_cache('frozen').script_levels[5].level.skin
219+
end
211220
end

dashboard/test/test_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class ActiveSupport::TestCase
2525

2626
setup do
2727
set_env :test
28+
29+
AWS::S3.stubs(:upload_to_bucket).raises("Don't actually upload anything to S3 in tests... mock it if you want to test it")
2830
end
2931

3032
teardown do

pegasus/sites.v3/hourofcode.com/public/prizes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ One lucky school in ***every*** U.S. state (+ Washington D.C.) won $10,000 worth
4646
7:30 AM PST - [Cory Booker](http://www.youtube.com/watch?v=wD0Heuvv87I) <br />
4747
10:00 AM PST - [JR Hildebrand](http://www.youtube.com/watch?v=DfhAdnosy58) <br />
4848
11:00 AM PST - [Clara Shih](http://www.youtube.com/watch?v=2p7uhb1qulA) <br />
49-
12:00 PM PST - [Jessica Alba](http://www.youtube.com/watch?v=Kxm7PK-iS3c) <br />
49+
12:00 PM PST - [Jessica Alba](http://youtu.be/m4oEbAQbWCE) <br />
5050

5151
**THURSDAY**, December 11 <br />
5252
5:30 AM PST - [Karlie Kloss](http://www.youtube.com/watch?v=6SzsRGTmjy0) <br />

0 commit comments

Comments
 (0)