chiark / gitweb /
Fix duplication of items in feeds.
authorSimon Tatham <anakin@pobox.com>
Mon, 8 Jan 2024 19:20:54 +0000 (19:20 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 8 Jan 2024 19:20:54 +0000 (19:20 +0000)
When we request any part of the contents of a feed from the server, it
provides us with followup links we can use to extend the same feed
further into the past or future. But if we're extending it further
into the past than we had, we shouldn't save the future link we get
back, because it's not as good as the future link we already had. And
vice versa.

The effect of this bug was that after extending a feed into the past,
the next extension into the future would start from the past
fragment's future extension and re-retrieve all the items we already
had. And we wouldn't notice, and would store a second copy of all
their ids in our list.

src/client.rs

index 7f0110c9b868ba54f17576c44e6db04059f3b358..e16d92e34b31a3e5dafbfb69bcf3fb7f048d2d30 100644 (file)
@@ -837,8 +837,19 @@ impl Client {
                     // Confusingly, the Mastodon protocol considers
                     // "next" to be heading into the past and "prev"
                     // the future.
-                    Some("next") => feed.extend_past = Some(link.queries),
-                    Some("prev") => feed.extend_future = Some(link.queries),
+                    //
+                    // We only keep the extension link for directions
+                    // that are the current frontier. If we're
+                    // extending an existing feed further into the
+                    // past, then the future link we have already is
+                    // better than the new one (which will cause us to
+                    // re-fetch stuff we already had). And vice versa.
+                    Some("next") => if ext != FeedExtend::Future {
+                        feed.extend_past = Some(link.queries);
+                    }
+                    Some("prev") => if ext != FeedExtend::Past {
+                        feed.extend_future = Some(link.queries);
+                    }
                     _ => (),
                 }
             }