mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Small UrlService optimisations
no issue - rename the config option to disable preloading the urls - always expose the urlservice as singleton - do the initialisation of the service inside the constructor
This commit is contained in:
parent
6d87703c2e
commit
7d99ee8466
3 changed files with 33 additions and 35 deletions
|
@ -11,6 +11,7 @@
|
||||||
* - overrides is the first package to load
|
* - overrides is the first package to load
|
||||||
*/
|
*/
|
||||||
require('./overrides');
|
require('./overrides');
|
||||||
|
require('./services/url');
|
||||||
|
|
||||||
// Module dependencies
|
// Module dependencies
|
||||||
var debug = require('ghost-ignition').debug('boot:init'),
|
var debug = require('ghost-ignition').debug('boot:init'),
|
||||||
|
@ -28,7 +29,6 @@ var debug = require('ghost-ignition').debug('boot:init'),
|
||||||
utils = require('./utils'),
|
utils = require('./utils'),
|
||||||
|
|
||||||
// Services that need initialisation
|
// Services that need initialisation
|
||||||
urlService = require('./services/url'),
|
|
||||||
apps = require('./services/apps'),
|
apps = require('./services/apps'),
|
||||||
xmlrpc = require('./services/xmlrpc'),
|
xmlrpc = require('./services/xmlrpc'),
|
||||||
slack = require('./services/slack'),
|
slack = require('./services/slack'),
|
||||||
|
@ -66,9 +66,7 @@ function init() {
|
||||||
// Initialize slack ping
|
// Initialize slack ping
|
||||||
slack.listen(),
|
slack.listen(),
|
||||||
// Initialize webhook pings
|
// Initialize webhook pings
|
||||||
webhooks.listen(),
|
webhooks.listen()
|
||||||
// Url Service
|
|
||||||
urlService.init()
|
|
||||||
);
|
);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
debug('Apps, XMLRPC, Slack done');
|
debug('Apps, XMLRPC, Slack done');
|
||||||
|
|
|
@ -19,12 +19,34 @@ const _ = require('lodash'),
|
||||||
utils = require('../../utils');
|
utils = require('../../utils');
|
||||||
|
|
||||||
class UrlService {
|
class UrlService {
|
||||||
constructor() {
|
constructor(options) {
|
||||||
this.resources = [];
|
this.resources = [];
|
||||||
|
|
||||||
_.each(resourceConfig, (config) => {
|
_.each(resourceConfig, (config) => {
|
||||||
this.resources.push(new Resource(config));
|
this.resources.push(new Resource(config));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// You can disable the url preload, in case we encounter a problem with the new url service.
|
||||||
|
if (options.disableUrlPreload) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.bind();
|
||||||
|
|
||||||
|
// Hardcoded routes
|
||||||
|
// @TODO figure out how to do this from channel or other config
|
||||||
|
// @TODO get rid of name concept (for compat with sitemaps)
|
||||||
|
UrlService.cacheRoute('/', {name: 'home'});
|
||||||
|
|
||||||
|
// @TODO figure out how to do this from apps
|
||||||
|
// @TODO only do this if subscribe is enabled!
|
||||||
|
UrlService.cacheRoute('/subscribe/', {});
|
||||||
|
|
||||||
|
// Register a listener for server-start to load all the known urls
|
||||||
|
events.on('server:start', (() => {
|
||||||
|
debug('URL service, loading all URLS');
|
||||||
|
this.loadResourceUrls();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
bind() {
|
bind() {
|
||||||
|
|
|
@ -1,32 +1,10 @@
|
||||||
const debug = require('ghost-ignition').debug('services:url:init'),
|
'use strict';
|
||||||
config = require('../../config'),
|
|
||||||
events = require('../../events'),
|
|
||||||
UrlService = require('./UrlService');
|
|
||||||
|
|
||||||
// @TODO we seriously should move this or make it do almost nothing...
|
const config = require('../../config'),
|
||||||
module.exports.init = function init() {
|
UrlService = require('./UrlService'),
|
||||||
// Temporary config value just in case this causes problems
|
urlService = new UrlService({
|
||||||
// @TODO delete this
|
disableUrlPreload: config.get('disableUrlPreload')
|
||||||
if (config.get('disableUrlService')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kick off the constructor
|
|
||||||
const urlService = new UrlService();
|
|
||||||
|
|
||||||
urlService.bind();
|
|
||||||
|
|
||||||
// Hardcoded routes
|
|
||||||
// @TODO figure out how to do this from channel or other config
|
|
||||||
// @TODO get rid of name concept (for compat with sitemaps)
|
|
||||||
UrlService.cacheRoute('/', {name: 'home'});
|
|
||||||
// @TODO figure out how to do this from apps
|
|
||||||
// @TODO only do this if subscribe is enabled!
|
|
||||||
UrlService.cacheRoute('/subscribe/', {});
|
|
||||||
|
|
||||||
// Register a listener for server-start to load all the known urls
|
|
||||||
events.on('server:start', function loadAllUrls() {
|
|
||||||
debug('URL service, loading all URLS');
|
|
||||||
urlService.loadResourceUrls();
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
// Singleton
|
||||||
|
module.exports = urlService;
|
||||||
|
|
Loading…
Add table
Reference in a new issue