mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00: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
|
||||
*/
|
||||
require('./overrides');
|
||||
require('./services/url');
|
||||
|
||||
// Module dependencies
|
||||
var debug = require('ghost-ignition').debug('boot:init'),
|
||||
|
@ -28,7 +29,6 @@ var debug = require('ghost-ignition').debug('boot:init'),
|
|||
utils = require('./utils'),
|
||||
|
||||
// Services that need initialisation
|
||||
urlService = require('./services/url'),
|
||||
apps = require('./services/apps'),
|
||||
xmlrpc = require('./services/xmlrpc'),
|
||||
slack = require('./services/slack'),
|
||||
|
@ -66,9 +66,7 @@ function init() {
|
|||
// Initialize slack ping
|
||||
slack.listen(),
|
||||
// Initialize webhook pings
|
||||
webhooks.listen(),
|
||||
// Url Service
|
||||
urlService.init()
|
||||
webhooks.listen()
|
||||
);
|
||||
}).then(function () {
|
||||
debug('Apps, XMLRPC, Slack done');
|
||||
|
|
|
@ -19,12 +19,34 @@ const _ = require('lodash'),
|
|||
utils = require('../../utils');
|
||||
|
||||
class UrlService {
|
||||
constructor() {
|
||||
constructor(options) {
|
||||
this.resources = [];
|
||||
|
||||
_.each(resourceConfig, (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() {
|
||||
|
|
|
@ -1,32 +1,10 @@
|
|||
const debug = require('ghost-ignition').debug('services:url:init'),
|
||||
config = require('../../config'),
|
||||
events = require('../../events'),
|
||||
UrlService = require('./UrlService');
|
||||
'use strict';
|
||||
|
||||
// @TODO we seriously should move this or make it do almost nothing...
|
||||
module.exports.init = function init() {
|
||||
// Temporary config value just in case this causes problems
|
||||
// @TODO delete this
|
||||
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();
|
||||
const config = require('../../config'),
|
||||
UrlService = require('./UrlService'),
|
||||
urlService = new UrlService({
|
||||
disableUrlPreload: config.get('disableUrlPreload')
|
||||
});
|
||||
};
|
||||
|
||||
// Singleton
|
||||
module.exports = urlService;
|
||||
|
|
Loading…
Add table
Reference in a new issue