mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-23 00:24:19 +08:00
Currently, when updating several settings in bulk, they are updated in a non-deterministic order. This means that if Setting B depends on Setting A being enabled, and we try to enable B and A together, there's a chance that fails. This is why we need to remove the up-front values_are_valid policy from the service as well. This change first sorts the settings topologically, i.e. in order of dependency, so if C depends on B depends on A, then we will update them in order [A, B, C].
32 lines
496 B
Ruby
Vendored
32 lines
496 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module SiteSettings
|
|
end
|
|
|
|
class SiteSettings::DependencyGraph
|
|
include TSort
|
|
|
|
def initialize(dependencies = {})
|
|
@dependencies = dependencies
|
|
end
|
|
|
|
def []=(setting, value)
|
|
dependencies[setting] = value
|
|
end
|
|
|
|
def order
|
|
@order ||= tsort
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :dependencies
|
|
|
|
def tsort_each_child(node, &block)
|
|
dependencies.fetch(node, []).each(&block)
|
|
end
|
|
|
|
def tsort_each_node(&block)
|
|
dependencies.each_key(&block)
|
|
end
|
|
end
|