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
This commit is contained in:
Cory McWilliams 2022-02-02 02:13:38 +00:00
parent c57b0a2f2f
commit a98a848bb7

View File

@ -55,7 +55,11 @@ function followingDeep(db, seed_ids, depth) {
function get_latest_sequence_for_author(author) { function get_latest_sequence_for_author(author) {
var sequence = 0; var sequence = 0;
ssb.sqlStream( 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], [author],
function(row) { function(row) {
if (row.sequence) { if (row.sequence) {
@ -97,6 +101,7 @@ ssb.addEventListener('connections', function(change, connection) {
connection.send_json({'name': ['blobs', 'createWants'], 'type': 'source', 'args': []}, function(message) { connection.send_json({'name': ['blobs', 'createWants'], 'type': 'source', 'args': []}, function(message) {
Object.keys(message.message).forEach(function(id) { Object.keys(message.message).forEach(function(id) {
if (message.message[id] < 0) { if (message.message[id] < 0) {
if (g_wants_requests[connection.id]) {
delete connection.active_blob_wants[id]; delete connection.active_blob_wants[id];
var blob = ssb.blobGet(id); var blob = ssb.blobGet(id);
if (blob) { if (blob) {
@ -104,6 +109,7 @@ ssb.addEventListener('connections', function(change, connection) {
out_message[id] = blob.byteLength; out_message[id] = blob.byteLength;
g_wants_requests[connection.id].send_json(out_message); g_wants_requests[connection.id].send_json(out_message);
} }
}
} else { } else {
var received_bytes = 0; var received_bytes = 0;
var expected_bytes = message.message[id]; var expected_bytes = message.message[id];