Skip to content
Browse files

Track an updated timestamp for the screen per #157.

  • Loading branch information...
1 parent 11dbd4e commit 950fdbc9e905d34170dd5bc92cf4088406eb6a4a @bamnet bamnet committed Mar 11, 2013
View
1 app/controllers/frontend/contents_controller.rb
@@ -32,6 +32,7 @@ def index
)
}
end
+ @screen.sometimes_mark_updated
end
# GET /frontend/1/fields/1/contents/1
View
1 app/controllers/frontend/screens_controller.rb
@@ -64,6 +64,7 @@ def setup
)
}
end
+ @screen.mark_updated
end
end
end
View
11 app/models/screen.rb
@@ -49,5 +49,16 @@ def gcd (a,b)
end
return gcd(b, a.modulo(b))
end
+
+ def mark_updated
+ update_column(:frontend_updated_at, Clock.time)
+ end
+
+ # Mark the screen as updated some percentage of the time.
+ # Doesn't always mark the screen as updated to avoid flooding the database
+ # but does it frequently enought for online / offline detection.
+ def sometimes_mark_updated(pct=0.1)
+ mark_updated if rand() <= pct
+ end
end
View
5 db/migrate/20130312041530_add_frontend_updated_at.rb
@@ -0,0 +1,5 @@
+class AddFrontendUpdatedAt < ActiveRecord::Migration
+ def change
+ add_column :screens, :frontend_updated_at, :datetime
+ end
+end
View
3 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130306065329) do
+ActiveRecord::Schema.define(:version => 20130312041530) do
create_table "activities", :force => true do |t|
t.integer "trackable_id"
@@ -171,6 +171,7 @@
t.datetime "updated_at", :null => false
t.integer "width"
t.integer "height"
+ t.datetime "frontend_updated_at"
end
create_table "submissions", :force => true do |t|

0 comments on commit 950fdbc

Please sign in to comment.
Something went wrong with that request. Please try again.