Skip to content

Commit

Permalink
when gluing stuff together for the map, don't overwrite synclets ever…
Browse files Browse the repository at this point in the history
…y time, they care about themselves too much, fixes #874
  • Loading branch information
quartzjer committed Feb 26, 2012
1 parent 5cf8d4f commit cf418b9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Common/node/lservicemanager.js
Expand Up @@ -119,6 +119,25 @@ exports.providers = function(types) {
return services;
};

// lutil.extend is YOUR MOM

This comment has been minimized.

Copy link
@othiym23

othiym23 Feb 27, 2012

Member

Can you maybe replace this with something that explains why this function exists / what led to it being created?

function fuckingMerge(alive, dead)

This comment has been minimized.

Copy link
@othiym23

othiym23 Feb 27, 2012

Member

This function name is going to be completely impenetrable within a week. Something that's a little less in-the-moment, please?

{
// we have to intelligently merge synclets array!
if(dead.synclets){
if(!alive.synclets) alive.synclets = [];
var ndx = {};
for(var i = 0; i < alive.synclets.length; i++) ndx[alive.synclets[i].name] = alive.synclets[i];
for(var i = 0; i < dead.synclets.length; i++) {
var s = dead.synclets[i];
if(ndx[s.name]) Object.keys(s).forEach( function(key){ ndx[s.name][key] = s[key] } );
if(!ndx[s.name]) alive.synclets.push(s);
}
}
// everything else dumb copy
Object.keys(dead).forEach(function(key){
if(key != "synclets") alive[key] = dead[key];
});
}

// update or install this file into the map
exports.mapUpsert = function (file) {
Expand All @@ -139,7 +158,7 @@ exports.mapUpsert = function (file) {
// synclets are in their own file, extend them in too
var sync = path.join(lconfig.lockerDir, path.dirname(file),"synclets.json");
if(path.existsSync(sync)) {
js = lutil.extend(js, JSON.parse(fs.readFileSync(sync, 'utf8')));
fuckingMerge(js, JSON.parse(fs.readFileSync(sync, 'utf8')));
}
} catch (E) {
logger.error("failed to upsert "+file+" due to "+E);
Expand All @@ -154,7 +173,7 @@ exports.mapUpsert = function (file) {
// if it exists already, merge it in and save it
if(serviceMap[js.handle]) {
logger.verbose("updating "+js.handle);
serviceMap[js.handle] = lutil.extend(serviceMap[js.handle], js);
fuckingMerge(serviceMap[js.handle], js);
exports.mapReload(js.handle);
// if it's running and updated, signal it to shutdown so new code/config is run at next request
if(js.pid) try {
Expand Down

1 comment on commit cf418b9

@othiym23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we need some specific functions that we understand and fit the usage patterns of our data, rather than hacking up jQuery code and random one-off methods.

Please sign in to comment.