core: Add backlog trigger to update lastmsgid
authorShane Synan <digitalcircuit36939@gmail.com>
Sun, 16 Apr 2017 04:13:59 +0000 (23:13 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 24 Apr 2017 19:53:17 +0000 (21:53 +0200)
commit1d1178f7d73ab19e62798f23c1d0cd5e0b4cdb59
treee164ba2a43b9b604bfe4508a19fd9a9bc7920457
parent3cf5c49e7753be48a994917fe898730add4292b1
core: Add backlog trigger to update lastmsgid

Add PostgreSQL function 'backlog_lastmsgid_update()' that sets the
'lastmsgid' of a buffer according to the latest message ID available.
Also add a PostgreSQL trigger 'backlog_lastmsgid_update' that acts
whenever a new message is inserted to or updated in the backlog
table.

Add two SQLite triggers, 'backlog_lastmsgid_update_trigger_insert'
for inserting messages into the backlog, and
'backlog_lastmsgid_update_trigger_update' for updating messages in
the backlog.  Both triggers update the 'lastmsgid' of a buffer
according to the latest message ID available.

Unfortunately, SQLite lacks niceties such as functions or complex
triggers, requiring two separate triggers to do the same thing.  Ah
well, SQLite is much easier to bundle and set up.

This fixes some cases where 'update_lastmsgid' was not being called
when it should, namely when inserting multiple messages.

NOTE:  Currently Quassel does not offer an option to delete
specific messages without deleting a buffer, nor to update the
message ID of existing messages (this would break many assumptions).
However, for completion-sake, the UPDATE triggers are included.
DELETE triggers should be added if individual message deletion is
added.

Thanks to justJanne for the suggestion and PostgreSQL code!
src/core/SQL/PostgreSQL/setup_061_add_function_backlog_lastmsgid_update.sql [new file with mode: 0644]
src/core/SQL/PostgreSQL/setup_062_add_trigger_backlog_lastmsgid_update.sql [new file with mode: 0644]
src/core/SQL/PostgreSQL/version/21/upgrade_000_add_function_backlog_lastmsgid_update.sql [new file with mode: 0644]
src/core/SQL/PostgreSQL/version/21/upgrade_001_add_trigger_backlog_lastmsgid_update.sql [new file with mode: 0644]
src/core/SQL/SQLite/setup_061_add_trigger_backlog_lastmsgid_update_direct_insert.sql [new file with mode: 0644]
src/core/SQL/SQLite/setup_062_add_trigger_backlog_lastmsgid_update_direct_update.sql [new file with mode: 0644]
src/core/SQL/SQLite/version/22/upgrade_000_add_trigger_backlog_lastmsgid_update_direct_insert.sql [new file with mode: 0644]
src/core/SQL/SQLite/version/22/upgrade_001_add_trigger_backlog_lastmsgid_update_direct_update.sql [new file with mode: 0644]
src/core/sql.qrc