From 68b7dc48bb25ea73190d850660e555bdb491e692 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 21 Jul 2014 21:15:03 -0700 Subject: the "page 2 shows up on top of page 1 when you wake up in the morning" bug. See the comments. --- mod/network.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'mod') diff --git a/mod/network.php b/mod/network.php index f12471467..1116f2f81 100644 --- a/mod/network.php +++ b/mod/network.php @@ -315,6 +315,21 @@ function network_content(&$a, $update = 0, $load = false) { } $simple_update = (($update) ? " and ( item.item_flags & " . intval(ITEM_UNSEEN) . " ) " : ''); + + // This fixes a very subtle bug so I'd better explain it. You wake up in the morning or return after a day + // or three and look at your matrix page - after opening up your browser. The first page loads just as it + // should. All of a sudden a few seconds later, page 2 will get inserted at the beginning of the page + // (before the page 1 content). The update code is actually doing just what it's supposed + // to, it's fetching posts that have the ITEM_UNSEEN bit set. But the reason that page 2 content is being + // returned in an UPDATE is because you hadn't gotten that far yet - you're still on page 1 and everything + // that we loaded for page 1 is now marked as seen. But the stuff on page 2 hasn't been. So... it's being + // treated as "new fresh" content because it is unseen. We need to distinguish it somehow from content + // which "arrived as you were reading page 1". We're going to do this + // by storing in your session the current UTC time whenever you LOAD a network page, and only UPDATE items + // which are both ITEM_UNSEEN and have "changed" since that time. Cross fingers... + + if($update && $_SESSION['loadtime']) + $simple_update .= " and item.changed > " . datetime_convert('UTC','UTC',$_SESSION['loadtime']); if($load) $simple_update = ''; @@ -345,6 +360,8 @@ function network_content(&$a, $update = 0, $load = false) { if($load) { + $_SESSION['loadtime'] = datetime_convert(); + // Fetch a page full of parent items for this page $r = q("SELECT distinct item.id AS item_id FROM item -- cgit v1.2.3