mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
DEV: Prevent removed keys from being resolved in the DAG (#26912)
This commit is contained in:
@ -91,7 +91,14 @@ export default class DAG {
|
|||||||
@bind
|
@bind
|
||||||
resolve() {
|
resolve() {
|
||||||
const result = [];
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,20 @@ module("Unit | Lib | DAG", function (hooks) {
|
|||||||
assert.deepEqual(keys, ["key1", "key2", "key4", "key3"]);
|
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) {
|
test("throws on bad positioning", function (assert) {
|
||||||
dag = new DAG();
|
dag = new DAG();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user