Skip to content

Commit 4c530e9

Browse files
committed
chore: optimize enqueue scripts
Resolves #73
1 parent 7a63e42 commit 4c530e9

File tree

3 files changed

+81
-18
lines changed

3 files changed

+81
-18
lines changed

Resources/enqueue-instances.sql

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
-- Queue all known instances.
2-
insert into ms_queued_instance (instance_id)
3-
select id as instance_id
4-
from "instance"
5-
on conflict do nothing;
1+
/*
2+
* === Very important note ===
3+
* This script uses unlogged writes which are NOT fail-safe!
4+
* Make sure to stop ModShark and Sharkey before executing.
5+
* Your instance data is not at risk, but ModShark's queues could be corrupted.
6+
*
7+
* Recommendation: increase checkpoint_segments to 32 or higher.
8+
* See https://stackoverflow.com/a/52271138 for details.
9+
*
10+
* https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-SET-LOGGED-UNLOGGED
11+
* https://www.postgresql.org/docs/current/sql-set-constraints.html
12+
*/
13+
14+
begin transaction;
15+
16+
-- Queue all known instances.
17+
set constraints all deferred;
18+
alter table ms_queued_instance set unlogged;
19+
insert into ms_queued_instance (instance_id)
20+
select id as instance_id
21+
from "instance"
22+
on conflict do nothing;
23+
alter table ms_queued_instance set logged;
24+
set constraints all immediate;
625

726
-- Reset flags to ensure new instances get processed.
827
delete from ms_flagged_instance f
928
using ms_queued_instance q
10-
where q.instance_id = f.instance_id;
29+
where q.instance_id = f.instance_id;
30+
31+
commit;

Resources/enqueue-notes.sql

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
-- Queue all known notes.
2-
insert into ms_queued_note (note_id)
3-
select id as note_id
4-
from "note"
5-
on conflict do nothing;
1+
/*
2+
* === Very important note ===
3+
* This script uses unlogged writes which are NOT fail-safe!
4+
* Make sure to stop ModShark and Sharkey before executing.
5+
* Your instance data is not at risk, but ModShark's queues could be corrupted.
6+
*
7+
* Recommendation: increase checkpoint_segments to 32 or higher.
8+
* See https://stackoverflow.com/a/52271138 for details.
9+
*
10+
* https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-SET-LOGGED-UNLOGGED
11+
* https://www.postgresql.org/docs/current/sql-set-constraints.html
12+
*/
13+
14+
begin transaction;
15+
16+
-- Queue all known notes.
17+
set constraints all deferred;
18+
alter table ms_queued_note set unlogged;
19+
insert into ms_queued_note (note_id)
20+
select id as note_id
21+
from "note"
22+
on conflict do nothing;
23+
alter table ms_queued_note set logged;
24+
set constraints all immediate;
625

726
-- Reset flags to ensure new notes get processed.
827
delete from ms_flagged_note f
928
using ms_queued_note q
10-
where q.note_id = f.note_id;
29+
where q.note_id = f.note_id;
30+
31+
commit;

Resources/enqueue-users.sql

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
-- Queue all known users.
2-
insert into ms_queued_user (user_id)
3-
select id as user_id
4-
from "user"
5-
on conflict do nothing;
1+
/*
2+
* === Very important note ===
3+
* This script uses unlogged writes which are NOT fail-safe!
4+
* Make sure to stop ModShark and Sharkey before executing.
5+
* Your instance data is not at risk, but ModShark's queues could be corrupted.
6+
*
7+
* Recommendation: increase checkpoint_segments to 32 or higher.
8+
* See https://stackoverflow.com/a/52271138 for details.
9+
*
10+
* https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-SET-LOGGED-UNLOGGED
11+
* https://www.postgresql.org/docs/current/sql-set-constraints.html
12+
*/
13+
14+
begin transaction;
15+
16+
-- Queue all known users.
17+
set constraints all deferred;
18+
alter table ms_queued_user set unlogged;
19+
insert into ms_queued_user (user_id)
20+
select id as user_id
21+
from "user"
22+
on conflict do nothing;
23+
alter table ms_queued_user set logged;
24+
set constraints all immediate;
625

726
-- Reset flags to ensure new users get processed.
827
delete from ms_flagged_user f
928
using ms_queued_user q
10-
where q.user_id = f.user_id;
29+
where q.user_id = f.user_id;
30+
31+
commit;

0 commit comments

Comments
 (0)