Skip to content

Commit

Permalink
chore: optimize enqueue scripts
Browse files Browse the repository at this point in the history
Resolves #73
  • Loading branch information
warriordog committed Aug 7, 2024
1 parent 7a63e42 commit 4c530e9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 18 deletions.
33 changes: 27 additions & 6 deletions Resources/enqueue-instances.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
-- Queue all known instances.
insert into ms_queued_instance (instance_id)
select id as instance_id
from "instance"
on conflict do nothing;
/*
* === Very important note ===
* This script uses unlogged writes which are NOT fail-safe!
* Make sure to stop ModShark and Sharkey before executing.
* Your instance data is not at risk, but ModShark's queues could be corrupted.
*
* Recommendation: increase checkpoint_segments to 32 or higher.
* See https://stackoverflow.com/a/52271138 for details.
*
* https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-SET-LOGGED-UNLOGGED
* https://www.postgresql.org/docs/current/sql-set-constraints.html
*/

begin transaction;

-- Queue all known instances.
set constraints all deferred;
alter table ms_queued_instance set unlogged;
insert into ms_queued_instance (instance_id)
select id as instance_id
from "instance"
on conflict do nothing;
alter table ms_queued_instance set logged;
set constraints all immediate;

-- Reset flags to ensure new instances get processed.
delete from ms_flagged_instance f
using ms_queued_instance q
where q.instance_id = f.instance_id;
where q.instance_id = f.instance_id;

commit;
33 changes: 27 additions & 6 deletions Resources/enqueue-notes.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
-- Queue all known notes.
insert into ms_queued_note (note_id)
select id as note_id
from "note"
on conflict do nothing;
/*
* === Very important note ===
* This script uses unlogged writes which are NOT fail-safe!
* Make sure to stop ModShark and Sharkey before executing.
* Your instance data is not at risk, but ModShark's queues could be corrupted.
*
* Recommendation: increase checkpoint_segments to 32 or higher.
* See https://stackoverflow.com/a/52271138 for details.
*
* https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-SET-LOGGED-UNLOGGED
* https://www.postgresql.org/docs/current/sql-set-constraints.html
*/

begin transaction;

-- Queue all known notes.
set constraints all deferred;
alter table ms_queued_note set unlogged;
insert into ms_queued_note (note_id)
select id as note_id
from "note"
on conflict do nothing;
alter table ms_queued_note set logged;
set constraints all immediate;

-- Reset flags to ensure new notes get processed.
delete from ms_flagged_note f
using ms_queued_note q
where q.note_id = f.note_id;
where q.note_id = f.note_id;

commit;
33 changes: 27 additions & 6 deletions Resources/enqueue-users.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
-- Queue all known users.
insert into ms_queued_user (user_id)
select id as user_id
from "user"
on conflict do nothing;
/*
* === Very important note ===
* This script uses unlogged writes which are NOT fail-safe!
* Make sure to stop ModShark and Sharkey before executing.
* Your instance data is not at risk, but ModShark's queues could be corrupted.
*
* Recommendation: increase checkpoint_segments to 32 or higher.
* See https://stackoverflow.com/a/52271138 for details.
*
* https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-SET-LOGGED-UNLOGGED
* https://www.postgresql.org/docs/current/sql-set-constraints.html
*/

begin transaction;

-- Queue all known users.
set constraints all deferred;
alter table ms_queued_user set unlogged;
insert into ms_queued_user (user_id)
select id as user_id
from "user"
on conflict do nothing;
alter table ms_queued_user set logged;
set constraints all immediate;

-- Reset flags to ensure new users get processed.
delete from ms_flagged_user f
using ms_queued_user q
where q.user_id = f.user_id;
where q.user_id = f.user_id;

commit;

0 comments on commit 4c530e9

Please sign in to comment.