Copy lastmsgid fetch limit improvements from PostgreSQL to SQLite,
improving performance by not requiring scanning from the start of the
backlog table to the present.
This builds upon pull request #273, including the original intent of
improving performance for unread backlog fetching. The original pull
request left out these lines when applying the PostgreSQL changes to
SQLite.
NOTE: The client-side generating these invalid values should be
fixed in future commits.
SELECT messageid, time, type, flags, sender, message
FROM backlog
JOIN sender ON backlog.senderid = sender.senderid
-WHERE bufferid = :bufferid
- AND backlog.messageid >= :firstmsg
+WHERE backlog.messageid >= :firstmsg
+ AND backlog.messageid <= (SELECT buffer.lastmsgid FROM buffer WHERE buffer.bufferid = :bufferid)
+ AND bufferid = :bufferid
ORDER BY messageid DESC
LIMIT :limit
FROM backlog
JOIN sender ON backlog.senderid = sender.senderid
WHERE bufferid = :bufferid
+AND backlog.messageid <= (SELECT buffer.lastmsgid FROM buffer WHERE buffer.bufferid = :bufferid)
ORDER BY messageid DESC
LIMIT :limit