<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,8 +1,8 @@
 module Memoria
   class &lt;&lt; self
-    def new(start_clock = true, clock_timeout = 30)
+    def new(start_clock = true, clock_interval = 30)
       data_mapper_setup
-      Clock.run(clock_timeout) if start_clock
+      Clock.run(clock_interval) if start_clock
       Sinatra::Application
     end
 </diff>
      <filename>app/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,11 +2,11 @@ class Clock
   @@mutex = Mutex.new
 
   class &lt;&lt; self
-    def run(timeout = 30)
+    def run(interval = 30)
       # TODO find a proper way to execute in background without forking
       fork do
         EventMachine.run do
-          EventMachine::PeriodicTimer.new(timeout) do
+          EventMachine::PeriodicTimer.new(interval) do
             servers.each do |server|
               EventMachine.defer proc { server.write_statistics }
             end</diff>
      <filename>app/clock.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,6 +15,7 @@ class Server
   property :host, String
   property :port, String
   has n, :snapshots
+  has 1, :latest_snapshot, :class_name =&gt; &quot;Snapshot&quot;, :limit =&gt; 1, :order =&gt; [:created_at.desc]
 
   validates_present :name, :host, :port
   validates_format  :name, :with =&gt; /^[0-9a-z]*$/i
@@ -22,14 +23,16 @@ class Server
 
   class &lt;&lt; self
     def overall_stats
+      # TODO eager loading for latest_snapshot
+      # TODO Enumerable#inject is slow, replace with a C style
       all.inject(BLANK_STATS.dup) do |result, server|
-        result[:servers_count]              += 1
-        if server.alive?
-          result[:servers_alive]            += 1
-          result[:used_memory]              += server.used_memory.to_i
-          result[:total_connections]        += server.total_connections_received.to_i
-          result[:current_connections]      += server.connected_clients.to_i
-          result[:total_commands_processed] += server.total_commands_processed.to_i
+        result[:servers_count]            += 1
+        if snapshot = server.latest_snapshot
+          result[:servers_alive]            += snapshot.alive ? 1 : 0
+          result[:used_memory]              += snapshot.used_memory
+          result[:total_connections]        += snapshot.total_connections_received
+          result[:current_connections]      += snapshot.connected_clients
+          result[:total_commands_processed] += snapshot.total_commands_processed
         end
         result
       end</diff>
      <filename>app/models/server.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,9 +4,9 @@ class Snapshot
   property   :id,                         Serial
   belongs_to :server
   property   :alive,                      Boolean
-  property   :used_memory,                Integer
-  property   :total_connections_received, Integer
-  property   :connected_clients,          Integer
-  property   :total_commands_processed,   Integer
+  property   :used_memory,                Integer, :default =&gt; 0
+  property   :total_connections_received, Integer, :default =&gt; 0
+  property   :connected_clients,          Integer, :default =&gt; 0
+  property   :total_commands_processed,   Integer, :default =&gt; 0
   property   :created_at,                 DateTime
 end
\ No newline at end of file</diff>
      <filename>app/models/snapshot.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,7 @@ port 6379
 # bind 127.0.0.1
 
 # Close the connection after a client is idle for N seconds
-timeout 5
+timeout 300
 
 # Save the DB on disk:
 #</diff>
      <filename>spec/config/single.conf</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>64a91c1ac77369f651fbd9feb7ea993be2950544</id>
    </parent>
  </parents>
  <author>
    <name>Luca Guidi</name>
    <email>guidi.luca@gmail.com</email>
  </author>
  <url>http://github.com/jodosha/memoria/commit/3aea69ee06bda3546851a05c6d55de2043572136</url>
  <id>3aea69ee06bda3546851a05c6d55de2043572136</id>
  <committed-date>2009-06-14T15:51:49-07:00</committed-date>
  <authored-date>2009-06-14T15:51:49-07:00</authored-date>
  <message>Read statistics from the database instead of calculate in real time</message>
  <tree>6690d105e662b1aa33ccc5df5dedebed91fec73a</tree>
  <committer>
    <name>Luca Guidi</name>
    <email>guidi.luca@gmail.com</email>
  </committer>
</commit>
