* JSONCache for caching JSON data (vs reading + parsing every time)

* Minor changes
This commit is contained in:
Bryan Ashby 2015-07-19 21:49:48 -06:00
parent 306e84b323
commit 89adc83fc6
9 changed files with 149 additions and 52 deletions

View File

@ -458,7 +458,6 @@ function display(options, cb) {
var continous = false;
/*
parser.on('row update', function rowUpdate(row) {
if(row >= nextPauseTermHeight) {
if(!continous && 'termHeight' === options.pause) {
@ -475,7 +474,6 @@ function display(options, cb) {
nextPauseTermHeight += options.client.term.termHeight;
}
});
*/
parser.on('mci', function mciEncountered(mciInfo) {
@ -507,7 +505,7 @@ function display(options, cb) {
mciPosQueue.push(mapKey);
options.client.term.rawWrite(ansi.queryPos());
options.client.term.write(ansi.queryPos(), false);
}
});
@ -542,12 +540,12 @@ function display(options, cb) {
}
if(ansiFont.length > 1) {
options.client.term.rawWrite(ansiFont);
options.client.term.write(ansiFont, false);
}
if(iceColors) {
options.client.term.rawWrite(ansi.blinkToBrightIntensity());
options.client.term.write(ansi.blinkToBrightIntensity(), false);
}
parser.reset(options.art);

View File

@ -124,6 +124,11 @@ function connectEntry(client) {
//
displayBanner(term);
/*
theme.displayThemeArt({client : client, name : 'DM-ENIG2.ANS'}, function onArt() {
});*/
setTimeout(function onTimeout() {
client.gotoMenuModule( { name : Config.firstMenu });
}, 500);

View File

@ -28,22 +28,6 @@ function FTNMailPacket(options) {
var self = this;
self.KLUDGE_PREFIX = '\x01';
/*
this.loadNodeAddresses = function() {
if(Config.networks) {
for(var name in Config.networks) {
if(!Config.networks[name].address) {
continue;
}
this.nodeAddresses[name] = Config.networks[name].address;
}
}
};
this.loadNodeAddresses();
*/
this.getPacketHeaderAddress = function() {
return {
zone : self.packetHeader.destZone,

View File

@ -43,18 +43,6 @@ function getDateFromFtnDateTime(dateTime) {
return (new Date(Date.parse(dateTime))).toISOString();
}
function getFormattedFTNAddress3D(zone, net, node) {
return util.format('%d:%d/%d', zone, net, node);
}
function getFormattedFTNAddress4D(zone, net, node, point) {
return util.format('%d:%d/%d.%d', zone, net, node, point);
}
function getFormattedFTNAddress5D(zone, net, node, point, domain) {
// :TODO:
}
function getFormattedFTNAddress(address, dimensions) {
var addr = util.format('%d:%d', address.zone, address.net);
switch(dimensions) {

65
core/json_cache.js Normal file
View File

@ -0,0 +1,65 @@
/* jslint node: true */
'use strict';
var Config = require('./config.js').config;
var Log = require('./logger.js').log;
var paths = require('path');
var fs = require('fs');
var Gaze = require('gaze').Gaze;
var stripJsonComments = require('strip-json-comments');
var assert = require('assert');
module.exports = exports = new JSONCache();
function JSONCache() {
var self = this;
this.cache = {}; // filePath -> JSON
this.gaze = new Gaze();
this.reCacheJSONFromFile = function(filePath, cb) {
fs.readFile(filePath, { encoding : 'utf-8' }, function fileRead(err, data) {
try {
self.cache[filePath] = JSON.parse(stripJsonComments(data));
cb(null, self.cache[filePath]);
} catch(e) {
cb(e);
}
});
};
this.gaze.on('error', function gazeErr(err) {
});
this.gaze.on('changed', function fileChanged(filePath) {
assert(filePath in self.cache);
Log.info( { filePath : filePath }, 'JSON file changed; recaching');
self.reCacheJSONFromFile(filePath, function reCached(err) {
if(err) {
Log.error( { error : err, filePath : filePath } , 'Error recaching JSON');
}
});
});
}
JSONCache.prototype.getJSON = function(fileName, cb) {
var self = this;
var filePath = paths.join(Config.paths.mods, fileName);
console.log(filePath)
if(filePath in this.cache) {
cb(null, this.cache[filePath]);
} else {
this.reCacheJSONFromFile(filePath, function fileCached(err, json) {
if(!err) {
self.gaze.add(filePath);
}
cb(err, json);
});
}
}

View File

@ -8,6 +8,7 @@ var conf = require('./config.js'); // :TODO: remove me!
var Config = require('./config.js').config;
var asset = require('./asset.js');
var theme = require('./theme.js');
var jsonCache = require('./json_cache.js');
var fs = require('fs');
var paths = require('path');
@ -22,28 +23,13 @@ exports.getFormConfigByIDAndMap = getFormConfigByIDAndMap;
exports.handleAction = handleAction;
exports.applyThemeCustomization = applyThemeCustomization;
function loadModJSON(fileName, cb) {
// :TODO: really need to cache menu.json and prompt.json only reloading if they change - see chokidar & gaze npms
var filePath = paths.join(Config.paths.mods, fileName);
fs.readFile(filePath, { encoding : 'utf8' }, function jsonData(err, data) {
try {
var json = JSON.parse(stripJsonComments(data));
cb(null, json);
} catch(e) {
cb(e);
}
});
}
function getMenuConfig(name, cb) {
var menuConfig;
async.waterfall(
[
function loadMenuJSON(callback) {
loadModJSON('menu.json', function loaded(err, menuJson) {
jsonCache.getJSON('menu.json', function loaded(err, menuJson) {
callback(err, menuJson);
});
},
@ -57,7 +43,7 @@ function getMenuConfig(name, cb) {
},
function loadPromptJSON(callback) {
if(_.isString(menuConfig.prompt)) {
loadModJSON('prompt.json', function loaded(err, promptJson) {
jsonCache.getJSON('prompt.json', function loaded(err, promptJson) {
callback(err, promptJson);
});
} else {

View File

@ -19,6 +19,7 @@ exports.getRandomTheme = getRandomTheme;
exports.initAvailableThemes = initAvailableThemes;
exports.displayThemeArt = displayThemeArt;
// :TODO: use JSONCache here... may need to fancy it up a bit in order to have events for after re-cache, e.g. to update helpers below:
function loadTheme(themeID, cb) {
var path = paths.join(Config.paths.themes, themeID, 'theme.json');

52
mods/art/test.ans Normal file
View File

@ -0,0 +1,52 @@
You should never see this!
... nor this
[?33h
 fONT tEST
 ~~~~~~~~~
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F
---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
0 |NUL|  |  |  |  |  |  |  |BS |HT |LF | | |CR |  |  
1 |  |  |  |  |  |  |  |  |  |  |EOF|ESC|  |  |  |  
2 | | ! | " | # | $ | % | & | ' | ( | ) | * | + | , | - | . | / 
3 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ? 
---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
4 | @ | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O 
5 | P | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ 
6 | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o 
7 | p | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ |  
---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
8 | € | <20> | | ƒ | „ | … | † | ‡ | ˆ | ‰ | Š | | Œ | <20> | Ž | <20> 
9 | <20> | | | “ | ” | • | | — | ˜ | ™ | š | | œ | <20> | ž | Ÿ 
A |   | ¡ | ¢ | £ | ¤ | ¥ | ¦ | § | ¨ | © | ª | « | ¬ | ­ | ® | ¯ 
B | ° | ± | ² | ³ | ´ | µ | ¶ | · | ¸ | ¹ | º | » | ¼ | ½ | ¾ | ¿ 
---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
C | À | Á |  | à | Ä | Å | Æ | Ç | È | É | Ê | Ë | Ì | Í | Î | Ï 
D | Ð | Ñ | Ò | Ó | Ô | Õ | Ö | × | Ø | Ù | Ú | Û | Ü | Ý | Þ | ß 
E | à | á | â | ã | ä | å | æ | ç | è | é | ê | ë | ì | í | î | ï 
F | ð | ñ | ò | ó | ô | õ | ö | ÷ | ø | ù | ú | û | ü | ý | þ | ÿ 
 cOLOR tEST
 ~~~~~~~~~~
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û
°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û


View File

@ -468,6 +468,8 @@
"VM1" : {
"items" : [
"Defaults - DOS ANSI",
"bw_mindgames.ans - DOS",
"test.ans - DOS",
"Defaults - Amiga",
"Pause at Term Height"
],
@ -480,6 +482,14 @@
{
"value" : { "1" : 0 },
"action" : "@menu:demoDefaultsDosAnsi"
},
{
"value" : { "1" : 1 },
"action" : "@menu:demoDefaultsDosAnsi_bw_mindgames"
},
{
"value" : { "1" : 2 },
"action" : "@menu:demoDefaultsDosAnsi_test"
}
]
}
@ -488,7 +498,15 @@
}
},
"demoDefaultsDosAnsi" : {
"art" : "WE-CIZB.ANS",
"art" : "DM-ENIG2.ANS",
"options" : { "cls" : true }
},
"demoDefaultsDosAnsi_bw_mindgames" : {
"art" : "bw_mindgames.ans",
"options" : { "cls" : true }
},
"demoDefaultsDosAnsi_test" : {
"art" : "test.ans",
"options" : { "cls" : true }
},
"demoFullScreenEditor" : {