Commit dae87797 authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Storing page time indexed by the hash of the URL

Let's save up some space, I don't really like seeing the URL used twice.
parent e8286661
String.prototype.hashCode = function(){
var hash = 0;
if (this.length == 0) return hash;
for (var i = 0; i < this.length; i++) {
var char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
return hash;
......@@ -284,19 +284,20 @@
(fn [app-state [_ tab time]]
(let [url-times (get-in app-state url-time-path)
url-key (:url tab)
url (or (:url tab) "")
url-key (.hashCode url)
url-time (or (get url-times url-key)
{:url (:url tab)
:time 0
:timestamp 0})
;; Don't track two messages too close
track? (and (not-empty url-key)
;; Don't track two messages too close together
track? (and (not= 0 url-key)
(< 100 (- (now) (:timestamp url-time))))
new-time (assoc url-time :time (+ (:time url-time) time)
:title (:title tab)
:favIconUrl (:favIconUrl tab)
:timestamp (now))]
(console/log time track? " milliseconds spent at " url-key)
(console/log time track? " milliseconds spent at " url-key tab)
(console/log " Previous " url-time)
(when track?
(dispatch [:data-set :url-times (assoc url-times url-key new-time)]))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment