Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
executable file 45 lines (34 sloc) 1.64 KB
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '..', 'config', 'environment')
require 'net/imap'
require 'net/http'
require 'rubygems'
require 'logger'
log = + " Warming up to process the clickstream..."
last_clickstream = Clickstream.last_unprocessed.last
clickstreams = Clickstream.unprocessed.all
clickstreams.each do |c| " Processing #{c.clickstreamable_type.to_s} with id #{c.clickstreamable_id.to_s}..."
unless c.clickstreamable_type.to_s =~ /(?:Home|Session)/i
object = c.clickstreamable
if object
object.viewed = object.viewed ? (object.viewed.to_i + c.cnt.to_i) : c.cnt.to_i
# clean up processed clickstreams ...
if last_clickstream " Cleaning the clickstream table from processed entries below id #{}..."
Clickstream.update_all('status=1', "clickstreamable_id is not null and clickstreamable_type is not null and status=0 and id<=#{}")
sql = "INSERT INTO clickstream_archives (SELECT * from clickstreams where status = 1 and id<=#{})"
Clickstream.delete_all("status=1 and id<=#{}")
# clean up the rest of the table... " Cleaning table from invalid data..."
sql = "INSERT INTO clickstream_archives (SELECT * from clickstreams where clickstreamable_id is null and clickstreamable_type is null)"
Clickstream.delete_all("clickstreamable_id is null and clickstreamable_type is null") + " Done and going to sleep..."
Something went wrong with that request. Please try again.