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();
|
||||
responsePb.setMerkle(JSON.stringify(trie));
|
||||
|
||||
for (let i = 0; i < newMessages.length; i++) {
|
||||
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);
|
||||
}
|
||||
newMessages.forEach(msg => responsePb.addMessages(msg));
|
||||
|
||||
res.set('Content-Type', 'application/actual-sync');
|
||||
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 });
|
||||
}
|
||||
|
||||
messages = messages.map(envPb => {
|
||||
const messagesDeserialized = messages.map(envPb => {
|
||||
let timestamp = envPb.getTimestamp();
|
||||
let msg = SyncPb.Message.deserializeBinary(envPb.getContent());
|
||||
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 {
|
||||
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