From a98a848bb7cee6e6203276a250c134d1cf08a830 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 2 Feb 2022 02:13:38 +0000 Subject: [PATCH] A crash fix, and try to fill in gaps? git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3812 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/ssb.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/core/ssb.js b/core/ssb.js index e8b71649..0bbad759 100644 --- a/core/ssb.js +++ b/core/ssb.js @@ -55,7 +55,11 @@ function followingDeep(db, seed_ids, depth) { function get_latest_sequence_for_author(author) { var sequence = 0; ssb.sqlStream( - 'SELECT MAX(sequence) AS sequence FROM messages WHERE author = ?1', + 'SELECT MIN(a.sequence) FROM messages a LEFT OUTER JOIN messages b ON a.author = b.author AND a.sequence + 1 = b.sequence WHERE a.author = ?1 AND b.content IS NULL', + // TODO: Should we never have allowed inserting if we couldn't + // validate previous? The query above helps us fill in gaps in + // feeds. + //'SELECT MAX(sequence) AS sequence FROM messages WHERE author = ?1', [author], function(row) { if (row.sequence) { @@ -97,12 +101,14 @@ ssb.addEventListener('connections', function(change, connection) { connection.send_json({'name': ['blobs', 'createWants'], 'type': 'source', 'args': []}, function(message) { Object.keys(message.message).forEach(function(id) { if (message.message[id] < 0) { - delete connection.active_blob_wants[id]; - var blob = ssb.blobGet(id); - if (blob) { - var out_message = {}; - out_message[id] = blob.byteLength; - g_wants_requests[connection.id].send_json(out_message); + if (g_wants_requests[connection.id]) { + delete connection.active_blob_wants[id]; + var blob = ssb.blobGet(id); + if (blob) { + var out_message = {}; + out_message[id] = blob.byteLength; + g_wants_requests[connection.id].send_json(out_message); + } } } else { var received_bytes = 0;