Commit 06da7cd2 authored by Alex Pooley's avatar Alex Pooley

Cache namespace traversal path

Work towards replacing recursive namespace queries with linear queries.
This commit tracks the path to each namespace, and future work will
replace recursive queries with queries that utilize this new column.
parent 35bd91b7
# frozen_string_literal: true
class ChangeTraversalIdsToBigint < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
change_column_type_concurrently :namespaces, :traversal_ids, 'bigint[]'
end
def down
undo_change_column_type_concurrently :namespaces, :traversal_ids
end
end
55b0e53343a5a053097d88842e1b8ebce7a61d168ba14f6866b5800d3b28a4fa
\ No newline at end of file
......@@ -150,6 +150,15 @@ $$;
COMMENT ON FUNCTION table_sync_function_2be879775d() IS 'Partitioning migration: table sync for audit_events table';
CREATE FUNCTION trigger_26c50fd02f49() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW."traversal_ids_for_type_change" := NEW."traversal_ids";
RETURN NEW;
END;
$$;
CREATE TABLE audit_events (
id bigint NOT NULL,
author_id integer NOT NULL,
......@@ -24554,6 +24563,8 @@ CREATE TRIGGER table_sync_trigger_b99eb6998c AFTER INSERT OR DELETE OR UPDATE ON
CREATE TRIGGER table_sync_trigger_ee39a25f9d AFTER INSERT OR DELETE OR UPDATE ON audit_events FOR EACH ROW EXECUTE PROCEDURE table_sync_function_2be879775d();
CREATE TRIGGER trigger_26c50fd02f49 BEFORE INSERT OR UPDATE ON namespaces FOR EACH ROW EXECUTE PROCEDURE trigger_26c50fd02f49();
CREATE TRIGGER trigger_has_external_issue_tracker_on_delete AFTER DELETE ON services FOR EACH ROW WHEN ((((old.category)::text = 'issue_tracker'::text) AND (old.active = true) AND (old.project_id IS NOT NULL))) EXECUTE PROCEDURE set_has_external_issue_tracker();
CREATE TRIGGER trigger_has_external_issue_tracker_on_insert AFTER INSERT ON services FOR EACH ROW WHEN ((((new.category)::text = 'issue_tracker'::text) AND (new.active = true) AND (new.project_id IS NOT NULL))) EXECUTE PROCEDURE set_has_external_issue_tracker();
......@@ -62,6 +62,10 @@ RSpec.describe Namespace::TraversalHierarchy, type: :model do
Namespace.update_all(traversal_ids: [])
end
before do
Namespace.update_all(traversal_ids: [])
end
it { is_expected.to match_array Namespace.all }
context 'when lock is true' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment