* Wrote a database reaper script to delete unused notes, notebooks, etc.
* Added some database indices to improve select performance.
This commit is contained in:
parent
0790463b8d
commit
bb89c42e60
5
NEWS
5
NEWS
|
@ -1,3 +1,8 @@
|
|||
1.2.2: March ?, 2008
|
||||
* Wrote a database reaper script to delete unused notes, notebooks, etc.
|
||||
* Added some database indices to improve select performance.
|
||||
* Now scrolling the page vertically to show opened errors and messages.
|
||||
|
||||
1.2.1: February 29, 2008
|
||||
* Updated the front page of the site to look nicer and better explain things.
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
create index file_notebook_id_index on file using btree ( notebook_id );
|
||||
create index note_notebook_id_index on note using btree ( notebook_id );
|
|
@ -0,0 +1,117 @@
|
|||
-- Delete old demo users.
|
||||
delete from
|
||||
luminotes_user
|
||||
where
|
||||
username is null
|
||||
and
|
||||
luminotes_user.revision < now() - interval '1 day';
|
||||
|
||||
-- Delete permissions for users who no longer exist.
|
||||
delete from
|
||||
user_notebook
|
||||
where
|
||||
user_id not in (
|
||||
select id from luminotes_user_current
|
||||
);
|
||||
|
||||
-- Delete trash notebooks of forever-deleted notebooks, and all past revisions of them.
|
||||
delete from
|
||||
notebook
|
||||
where
|
||||
notebook.id in (
|
||||
select
|
||||
trash_id
|
||||
from
|
||||
notebook_current
|
||||
where
|
||||
id not in
|
||||
( select notebook_id from user_notebook )
|
||||
and
|
||||
notebook_current.revision < now() - interval '1 day'
|
||||
);
|
||||
|
||||
-- Delete forever-deleted notebooks, and all past revisions of them.
|
||||
delete from
|
||||
notebook
|
||||
where
|
||||
notebook.id in (
|
||||
select
|
||||
id
|
||||
from
|
||||
notebook_current
|
||||
where
|
||||
id not in
|
||||
( select notebook_id from user_notebook )
|
||||
and
|
||||
notebook_current.revision < now() - interval '1 day'
|
||||
);
|
||||
|
||||
-- Delete unused next ids, forever-deleted notes, and notes whose notebooks no longer exist.
|
||||
-- Also delete all past revisions of these notes.
|
||||
delete from
|
||||
note
|
||||
where
|
||||
note.id in (
|
||||
select
|
||||
id
|
||||
from
|
||||
note_current
|
||||
where (
|
||||
notebook_id is null or notebook_id not in
|
||||
( select notebook_id from notebook_current )
|
||||
)
|
||||
and
|
||||
note_current.revision < now() - interval '1 day'
|
||||
);
|
||||
|
||||
-- Delete unused file next ids and files whose notebooks or notes no longer exist.
|
||||
delete from
|
||||
file
|
||||
where (
|
||||
notebook_id is null or notebook_id not in
|
||||
( select notebook_id from notebook_current )
|
||||
or note_id not in
|
||||
( select note_id from note_current )
|
||||
)
|
||||
and
|
||||
file.revision < now() - interval '1 day';
|
||||
|
||||
-- Delete old notebook revisions.
|
||||
delete from
|
||||
notebook
|
||||
where
|
||||
revision not in (
|
||||
SELECT
|
||||
max( sub_notebook.revision ) as max
|
||||
from
|
||||
notebook sub_notebook
|
||||
where
|
||||
sub_notebook.id = notebook.id
|
||||
)
|
||||
and
|
||||
notebook.revision < now() - interval '1 week';
|
||||
|
||||
-- Delete old user revisions.
|
||||
delete from
|
||||
luminotes_user
|
||||
where
|
||||
revision not in (
|
||||
SELECT
|
||||
max( sub_luminotes_user.revision ) as max
|
||||
from
|
||||
luminotes_user sub_luminotes_user
|
||||
where
|
||||
sub_luminotes_user.id = luminotes_user.id
|
||||
)
|
||||
and
|
||||
luminotes_user.revision < now() - interval '1 week';
|
||||
|
||||
-- Delete permissions for notebooks that no longer exist.
|
||||
delete from
|
||||
user_notebook
|
||||
where
|
||||
notebook_id not in (
|
||||
select id from notebook_current
|
||||
);
|
||||
|
||||
vacuum analyze;
|
Reference in New Issue