mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 16:41:18 +08:00
DEV: Prevent removed keys from being resolved in the DAG (#26912)
This commit is contained in:
parent
4edc011d10
commit
e992cf1507
|
@ -91,7 +91,14 @@ export default class DAG {
|
|||
@bind
|
||||
resolve() {
|
||||
const result = [];
|
||||
this.#dag.each((key, value) => result.push({ key, value }));
|
||||
this.#dag.each((key, value) => {
|
||||
// We need to filter keys that do not exist in the rawData because the DAGMap will insert a vertex for
|
||||
// dependencies, for example if an item has a "before: search" dependency, the "search" vertex will be included
|
||||
// even if it was explicitly excluded from the raw data.
|
||||
if (this.has(key)) {
|
||||
result.push({ key, value });
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,20 @@ module("Unit | Lib | DAG", function (hooks) {
|
|||
assert.deepEqual(keys, ["key1", "key2", "key4", "key3"]);
|
||||
});
|
||||
|
||||
test("should resolve only existing keys", function (assert) {
|
||||
dag = new DAG();
|
||||
dag.add("key1", "value1");
|
||||
dag.add("key2", "value2", { before: "key1" });
|
||||
dag.add("key3", "value3");
|
||||
|
||||
dag.delete("key1");
|
||||
|
||||
const resolved = dag.resolve();
|
||||
const keys = resolved.map((pair) => pair.key);
|
||||
|
||||
assert.deepEqual(keys, ["key2", "key3"]);
|
||||
});
|
||||
|
||||
test("throws on bad positioning", function (assert) {
|
||||
dag = new DAG();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user