Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

cleanup on 83c0f41e4c, startup performance regression #465

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/unhangout-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var logger = require('./logging').getLogger(),
var UnhangoutDb = function(options) {
this.options = options;
};
var _origUsersComparator;
_.extend(UnhangoutDb.prototype, events.EventEmitter.prototype, {
init: function(callback) {
_.bindAll(this, "loadModels");
Expand All @@ -19,8 +18,6 @@ _.extend(UnhangoutDb.prototype, events.EventEmitter.prototype, {
this.options.UNHANGOUT_REDIS_HOST
);
this.users = new models.ServerUserList();
_origUsersComparator = this.users.comparator;
this.users.comparator = undefined;
this.events = new models.ServerEventList();
this.permalinkSessions = new models.ServerSessionList();

Expand Down Expand Up @@ -97,19 +94,24 @@ _.extend(UnhangoutDb.prototype, events.EventEmitter.prototype, {
// representing each of the objects of that type in redis. It simply
// needs to construct matching objects. To add a new type, just add a
// matching entry in loaders and follow the format.
// NOTE: For any new types that are added, be sure to add {sort: false}
// to the options for the calls to set/add to objects in collections,
// and if a final sort is needed, call it on the collection after
// everything has been loaded -- otherwise potentially huge impacts on
// startup performance may occur!
var that = this;
var loaders = [
["user/*", function(callback, attrs, key) {
var newUser = new models.ServerUser(attrs);
// no need to save since we're pulling from the
// database to begin with.
that.users.add(newUser);
that.users.add(newUser, {sort: false});
callback();
}],

["event/?????", function(callback, attrs, key) {
var newEvent = new models.ServerEvent(attrs);
that.events.add(newEvent);
that.events.add(newEvent, {sort: false});
callback();
}],

Expand All @@ -134,7 +136,7 @@ _.extend(UnhangoutDb.prototype, events.EventEmitter.prototype, {
var newSession = new models.ServerSession(attrs, {
collection: event.get("sessions")
});
event.get("sessions").add(newSession);
event.get("sessions").add(newSession, {sort: false});
// Reset state as needed.
newSession.onRestart();

Expand All @@ -149,7 +151,7 @@ _.extend(UnhangoutDb.prototype, events.EventEmitter.prototype, {
// force these to be true. This fixes a transient condition where some
// keys in the db didn't have this set and it defaults to false.dw
newSession.set("isPermalinkSession", true);
that.permalinkSessions.add(newSession);
that.permalinkSessions.add(newSession, {sort: false});
// Reset state as needed.
newSession.onRestart();

Expand Down Expand Up @@ -207,7 +209,6 @@ _.extend(UnhangoutDb.prototype, events.EventEmitter.prototype, {
};
async.mapSeries(loaders, load, function(err, results) {
logger.info("Done loading models.");
that.users.comparator = _origUsersComparator;
that.users.sort();
callback();
});
Expand Down