From: Andrew Tridgell Date: Sun, 10 Oct 2010 02:35:02 +0000 (+1100) Subject: fixed CSV cache X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=747e25dfd92f9225bbcbdb5c9b181ffb507dcf87;p=tridge%2Fsolar.git fixed CSV cache --- diff --git a/live/graphs.js b/live/graphs.js index 400e0b0..21aee3e 100644 --- a/live/graphs.js +++ b/live/graphs.js @@ -46,20 +46,30 @@ function parse_date(s) { /* keep a cache of loaded CSV files */ CSV_Cache = new Array(); + /* - load a CSV file, returing column names and data + load a CSV file, returing column names and data via a callback */ function load_CSV(d, filename, callback) { /* maybe its in the global cache? */ if (CSV_Cache[filename] !== undefined) { + if (CSV_Cache[filename].pending) { + /* it might be pending */ + var q = CSV_Cache[filename].queue.length; + CSV_Cache[filename].queue[q] = {filename:filename, d:d, callback:callback}; + return; + } d.filename = CSV_Cache[filename].filename; d.labels = CSV_Cache[filename].labels; d.data = CSV_Cache[filename].data; + writeDebug("cache hit: " + filename); callback(d); return; } + CSV_Cache[filename] = { pending: true, queue: new Array()}; + /* async callback when the CSV is loaded */ @@ -85,7 +95,17 @@ function load_CSV(d, filename, callback) { } /* save into the global cache */ - CSV_Cache[caller.filename] = { filename: caller.filename, labels:labels, data:data }; + CSV_Cache[caller.filename].filename = filename; + CSV_Cache[caller.filename].labels = labels; + CSV_Cache[caller.filename].data = data; + for (var q=0; q