summaryrefslogtreecommitdiff
path: root/app/workers/pages/invalidate_domain_cache_worker.rb
blob: 1700b681b94715b75f0e280244e77d25455d1e1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module Pages
  class InvalidateDomainCacheWorker
    include Gitlab::EventStore::Subscriber

    idempotent!

    feature_category :pages

    def handle_event(event)
      domain_ids(event).each do |domain_id|
        ::Gitlab::Pages::CacheControl
          .for_domain(domain_id)
          .clear_cache
      end

      event.data.values_at(
        :root_namespace_id,
        :old_root_namespace_id,
        :new_root_namespace_id
      ).compact.uniq.each do |namespace_id|
        ::Gitlab::Pages::CacheControl
          .for_namespace(namespace_id)
          .clear_cache
      end
    end

    def domain_ids(event)
      ids = PagesDomain.ids_for_project(event.data[:project_id])

      ids << event.data[:domain_id] if event.data[:domain_id]

      ids
    end
  end
end