From 46cd796db552c66a7450e3c1d64e4fc4e6533efe Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 25 Jun 2019 13:43:15 +0200 Subject: [PATCH] label code that will need to change for editable metadata --- historyKeeper.js | 16 ++++++++-------- rpc.js | 2 +- storage/file.js | 6 +++++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/historyKeeper.js b/historyKeeper.js index 03c767506..169b14ffb 100644 --- a/historyKeeper.js +++ b/historyKeeper.js @@ -61,13 +61,13 @@ module.exports.create = function (cfg) { const cpIndex = []; let messageBuf = []; let validateKey; - let metadata; + let metadata; // FIXME METADATA let i = 0; store.readMessagesBin(channelName, 0, (msgObj, rmcb) => { let msg; i++; if (!validateKey && msgObj.buff.indexOf('validateKey') > -1) { - metadata = msg = tryParse(msgObj.buff.toString('utf8')); + metadata = msg = tryParse(msgObj.buff.toString('utf8')); // FIXME METADATA if (typeof msg === "undefined") { return rmcb(); } if (msg.validateKey) { validateKey = historyKeeperKeys[channelName] = msg; @@ -105,7 +105,7 @@ module.exports.create = function (cfg) { cpIndex: sliceCpIndex(cpIndex, i), offsetByHash: offsetByHash, size: size, - metadata: metadata, + metadata: metadata, // FIXME METADATA line: i }); }); @@ -438,16 +438,16 @@ module.exports.create = function (cfg) { so, let's just fall through... */ if (err) { return w(); } - if (!index || !index.metadata) { return void w(); } + if (!index || !index.metadata) { return void w(); } // FIXME METADATA // Store the metadata if we don't have it in memory if (!historyKeeperKeys[channelName]) { - historyKeeperKeys[channelName] = index.metadata; + historyKeeperKeys[channelName] = index.metadata; // FIXME METADATA } // And then check if the channel is expired. If it is, send the error and abort if (checkExpired(ctx, channelName)) { return void waitFor.abort(); } // Send the metadata to the user if (!lastKnownHash && index.cpIndex.length > 1) { - sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(index.metadata)], w); + sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(index.metadata)], w); // FIXME METADATA return; } w(); @@ -494,8 +494,8 @@ module.exports.create = function (cfg) { key.expire = expire; } historyKeeperKeys[channelName] = key; - storeMessage(ctx, chan, JSON.stringify(key), false, undefined); - sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(key)]); + storeMessage(ctx, chan, JSON.stringify(key), false, undefined); // FIXME METADATA + sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(key)]); // FIXME METADATA } // End of history message: diff --git a/rpc.js b/rpc.js index a69033cc1..9fb431708 100644 --- a/rpc.js +++ b/rpc.js @@ -1722,7 +1722,7 @@ RPC.create = function ( respond(e, [null, size, null]); }); case 'GET_METADATA': - return void getMetadata(Env, msg[1], function (e, data) { + return void getMetadata(Env, msg[1], function (e, data) { // FIXME METADATA WARN(e, msg[1]); respond(e, [null, data, null]); }); diff --git a/storage/file.js b/storage/file.js index 99272fc6f..196a83b32 100644 --- a/storage/file.js +++ b/storage/file.js @@ -60,6 +60,7 @@ var getMetadataAtPath = function (Env, path, cb) { stream.on('error', function (e) { complete(e); }); }; +// FIXME METADATA var getChannelMetadata = function (Env, channelId, cb) { var path = mkPath(Env, channelId); getMetadataAtPath(Env, path, cb); @@ -255,6 +256,9 @@ var listChannels = function (root, handler, cb) { var wait = w(); dirList.forEach(function (dir) { sema.take(function (give) { + // TODO modify the asynchronous bits here to keep less in memory at any given time + // list a directory -> process its contents with semaphores until less than N jobs are running + // then list the next directory... var nestedDirPath = Path.join(root, dir); Fs.readdir(nestedDirPath, w(give(function (err, list) { if (err) { return void handler(err); } // Is this correct? @@ -600,7 +604,7 @@ module.exports.create = function ( if (!isValidChannelId(channelName)) { return void cb(new Error('EINVAL')); } channelBytes(env, channelName, cb); }, - getChannelMetadata: function (channelName, cb) { + getChannelMetadata: function (channelName, cb) { // FIXME METADATA if (!isValidChannelId(channelName)) { return void cb(new Error('EINVAL')); } getChannelMetadata(env, channelName, cb); },