Commit e7218573 authored by yann300's avatar yann300

cache previously added import

parent 8af12855
...@@ -4,6 +4,7 @@ var swarmgw = require('swarmgw') ...@@ -4,6 +4,7 @@ var swarmgw = require('swarmgw')
var request = require('request') var request = require('request')
module.exports = { module.exports = {
previouslyHandled: {}, // cache import so we don't make the request at each compilation.
handleGithubCall: function (root, path, cb) { handleGithubCall: function (root, path, cb) {
return request.get( return request.get(
{ {
...@@ -61,6 +62,11 @@ module.exports = { ...@@ -61,6 +62,11 @@ module.exports = {
}, },
import: function (url, loadingCb, cb) { import: function (url, loadingCb, cb) {
var self = this
var imported = this.previouslyHandled[url]
if (imported) {
return cb(null, imported.content, imported.cleanUrl, imported.type, url)
}
var handlers = this.handlers() var handlers = this.handlers()
var found = false var found = false
...@@ -79,7 +85,11 @@ module.exports = { ...@@ -79,7 +85,11 @@ module.exports = {
cb('Unable to import "' + cleanUrl + '": ' + err) cb('Unable to import "' + cleanUrl + '": ' + err)
return return
} }
self.previouslyHandled[url] = {
content: content,
cleanUrl: cleanUrl,
type: handler.type
}
cb(null, content, cleanUrl, handler.type, url) cb(null, content, cleanUrl, handler.type, url)
}) })
} }
......
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