From 9dbd8be35891bb83abad647f9f488aa9a64722da Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 24 Feb 2023 12:37:42 +0000 Subject: Fix pagination of Misskey responses Misskey API, with `sinceId`, pages by `id ASC`, not descending as I thought. Also, allow using callbacks for paginated queries instead of accumulating all results (much nicer for the initial db filling) --- tweet-archive.pl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'tweet-archive.pl') diff --git a/tweet-archive.pl b/tweet-archive.pl index 1a7232b..38bb184 100644 --- a/tweet-archive.pl +++ b/tweet-archive.pl @@ -63,11 +63,14 @@ if ($conf->{misskey}) { $client->client->ua->add_handler( response_done => sub { push @responses, $_[0]; return } ); try { - my $latest_id = $store->latest_note_id; + my $latest_id = $store->latest_note_id // '0'; - for my $note ($client->timeline($latest_id)->@*) { - $store->store_note($note); - } + $client->timeline( + $latest_id, + sub($notes) { + $store->store_note($_) for $notes->@*; + }, + ); $store->store_misskey_following($client->following); $store->store_misskey_followers($client->followers); -- cgit v1.2.3