Tyler (tyler@nicecrew.digital)'s status on Wednesday, 19-Feb-2025 16:03:47 JST
-
Embed this notice
-- do rum indexing live with minimial degredation of performance for users.
DO $$
DECLARE
sleep_time FLOAT := 0.01; -- minimum value, ~100 records updated a second.
processed_count integer := 0;
total_count integer;
current_record RECORD;
new_time timestamp;
BEGIN
SELECT COUNT(*) INTO total_count FROM objects WHERE updated_at < NOW();
RAISE NOTICE 'Total rows to trigger RUM indexing on: %', total_count;
RAISE NOTICE 'Estimated time to completion: % minutes', sleep_time * total_count * 1.2/60;
FOR current_record IN
SELECT id, updated_at
FROM objects
LOOP
UPDATE objects SET updated_at = NOW()
WHERE id = current_record.id;
-- await trigger completion and release some computation time for live usage
processed_count = processed_count + 1;
IF processed_count % 500 = 0 THEN
COMMIT;
RAISE NOTICE 'Processed % rows', processed_count;
END IF;
PERFORM pg_sleep(sleep_time);
END LOOP;
RAISE NOTICE 'RUM Indexing complete';
END $$;