move messages generation into sync-full.js
This commit is contained in:
parent
b1a48f4f27
commit
4874b53c7c
2 changed files with 16 additions and 18 deletions
16
app-sync.js
16
app-sync.js
|
@ -136,21 +136,7 @@ app.post('/sync', async (req, res) => {
|
||||||
let responsePb = new SyncPb.SyncResponse();
|
let responsePb = new SyncPb.SyncResponse();
|
||||||
responsePb.setMerkle(JSON.stringify(trie));
|
responsePb.setMerkle(JSON.stringify(trie));
|
||||||
|
|
||||||
for (let i = 0; i < newMessages.length; i++) {
|
newMessages.forEach(msg => responsePb.addMessages(msg));
|
||||||
let msg = newMessages[i];
|
|
||||||
let envelopePb = new SyncPb.MessageEnvelope();
|
|
||||||
let messagePb = new SyncPb.Message();
|
|
||||||
|
|
||||||
messagePb.setDataset(msg.dataset);
|
|
||||||
messagePb.setRow(msg.row);
|
|
||||||
messagePb.setColumn(msg.column);
|
|
||||||
messagePb.setValue(msg.value);
|
|
||||||
|
|
||||||
envelopePb.setTimestamp(msg.timestamp);
|
|
||||||
envelopePb.setContent(messagePb.serializeBinary());
|
|
||||||
|
|
||||||
responsePb.addMessages(envelopePb);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.set('Content-Type', 'application/actual-sync');
|
res.set('Content-Type', 'application/actual-sync');
|
||||||
res.send(Buffer.from(responsePb.serializeBinary()));
|
res.send(Buffer.from(responsePb.serializeBinary()));
|
||||||
|
|
18
sync-full.js
18
sync-full.js
|
@ -15,7 +15,7 @@ const sync = sequential(async function syncAPI(messages, since, fileId) {
|
||||||
await actual.internal.send('load-budget', { id: fileId });
|
await actual.internal.send('load-budget', { id: fileId });
|
||||||
}
|
}
|
||||||
|
|
||||||
messages = messages.map(envPb => {
|
const messagesDeserialized = messages.map(envPb => {
|
||||||
let timestamp = envPb.getTimestamp();
|
let timestamp = envPb.getTimestamp();
|
||||||
let msg = SyncPb.Message.deserializeBinary(envPb.getContent());
|
let msg = SyncPb.Message.deserializeBinary(envPb.getContent());
|
||||||
return {
|
return {
|
||||||
|
@ -27,11 +27,23 @@ const sync = sequential(async function syncAPI(messages, since, fileId) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
let newMessages = await actual.internal.syncAndReceiveMessages(messages, since);
|
const newMessages = await actual.internal.syncAndReceiveMessages(messagesDeserialized, since);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
trie: actual.internal.timestamp.getClock().merkle,
|
trie: actual.internal.timestamp.getClock().merkle,
|
||||||
newMessages: newMessages
|
newMessages: newMessages.map(msg => {
|
||||||
|
const envelopePb = new SyncPb.MessageEnvelope();
|
||||||
|
|
||||||
|
const messagePb = new SyncPb.Message();
|
||||||
|
messagePb.setDataset(msg.dataset);
|
||||||
|
messagePb.setRow(msg.row);
|
||||||
|
messagePb.setColumn(msg.column);
|
||||||
|
messagePb.setValue(msg.value);
|
||||||
|
envelopePb.setTimestamp(msg.timestamp);
|
||||||
|
|
||||||
|
envelopePb.setContent(messagePb.serializeBinary());
|
||||||
|
return envelopePb;
|
||||||
|
})
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue