-
Notifications
You must be signed in to change notification settings - Fork 6
Description
There is usually not much of a reason to want to delete a page revision. Storage is cheap and we're dealing with text. But it might happen occasionally that you accidentally save a page with sensitive information on it and want that information to be purged from the universe. Today, that is pretty hard:
- Make note of the revision (timestamp) to be deleted.
- Make a new revision to evict the sensitive information from the FST5 table.
- Fire up SQLite and run a DELETE query with the page name and revision timestamp of interest.
I haven't put much thought into the UI at this point, but I think it would be good to have the option to delete either individual revisions or whole pages (all revision). Anyway, on the backend there are several things to think about. For starters, the trigger to remove a deleted page from the FTS5 table is completely broken:
-- After a page is deleted from the pages table,
-- delete the matching entry from the FTS table
CREATE TRIGGER pages_after_delete AFTER DELETE ON pages
BEGIN
INSERT INTO pages_fts (pages_fts, rowid, title, body)
VALUES ('delete', old.rowid, old.title, old.body);
END;This doesn't work because it's for a completely different kind of FTS table. It's actually from an earlier version of the schema before I fixed FTS5. The content of the trigger should actually just be a plain DELETE, something along these lines:
CREATE TRIGGER pages_after_delete AFTER DELETE ON pages
BEGIN
-- First, remove the (now potentially stale) FTS entry for this title.
DELETE FROM pages_fts WHERE title = old.title;
-- Then, if any other revisions for this title still exist, re-index
-- one of them. If no revisions remain, this does nothing, and the
-- page is correctly removed from the FTS index.
INSERT INTO pages_fts (title, body)
SELECT title, body FROM pages
WHERE title = old.title
LIMIT 1;
END;This likely needs an ORDER BY revision DESC LIMIT 1 tacked onto it so that the most recent revision of the page is the one that is stuffed into the index.
Anyway, that's about the shape of it.