load user pins in the database worker

This commit is contained in:
ansuz
2020-03-25 11:39:14 -04:00
parent 50e8893b24
commit 4ba36a9173
4 changed files with 58 additions and 28 deletions

View File

@@ -156,7 +156,6 @@ var getMultipleFileSize = function (Env, channels, cb) {
});
};
const batchUserPins = BatchRead("LOAD_USER_PINS");
var loadUserPins = function (Env, safeKey, cb) {
var session = Core.getSession(Env.Sessions, safeKey);
@@ -164,23 +163,14 @@ var loadUserPins = function (Env, safeKey, cb) {
return cb(session.channels);
}
batchUserPins(safeKey, cb, function (done) {
var ref = {};
var lineHandler = Pins.createLineHandler(ref, function (label, data) {
Env.Log.error(label, {
log: safeKey,
data: data,
});
});
// if channels aren't in memory. load them from disk
// TODO replace with readMessagesBin
Env.pinStore.getMessages(safeKey, lineHandler, function () {
// no more messages
// only put this into the cache if it completes
session.channels = ref.pins;
done(ref.pins); // FIXME no error handling?
Env.batchUserPins(safeKey, cb, function (done) {
Env.getPinState(safeKey, function (err, value) {
if (!err) {
// only put this into the cache if it completes
session.channels = value;
}
session.channels = value;
done(value);
});
});
};