Bug 1568895 - Ignore duplicate original files when found. r=jlast
authorLogan Smyth <loganfsmyth@gmail.com>
Thu, 22 Aug 2019 17:10:44 +0000
changeset 553230 1fbb898025967efb481820fb5b3158fc137ea538
parent 553229 0bab25d1df161291023cbd703eca35974d66e9a9
child 553231 1c5e22cd2378f68d90babb8e3b0aa0aaf62b72bc
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast
bugs1568895
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1568895 - Ignore duplicate original files when found. r=jlast Differential Revision: https://phabricator.services.mozilla.com/D43087
devtools/client/debugger/src/actions/sources/newSources.js
devtools/client/debugger/src/actions/sources/tests/newSources.spec.js
--- a/devtools/client/debugger/src/actions/sources/newSources.js
+++ b/devtools/client/debugger/src/actions/sources/newSources.js
@@ -5,17 +5,17 @@
 // @flow
 
 /**
  * Redux actions for the sources state
  * @module actions/sources
  */
 
 import { generatedToOriginalId } from "devtools-source-map";
-import { flatten } from "lodash";
+import { flatten, uniqBy } from "lodash";
 
 import {
   stringToSourceActorId,
   type SourceActor,
 } from "../../reducers/source-actors";
 import { insertSourceActors } from "../../actions/source-actors";
 import { makeSourceId } from "../../client/firefox/create";
 import { toggleBlackBox } from "./blackbox";
@@ -249,16 +249,19 @@ export function newQueuedSources(sourceI
 export function newOriginalSource(sourceInfo: OriginalSourceData) {
   return async ({ dispatch }: ThunkArgs) => {
     const sources = await dispatch(newOriginalSources([sourceInfo]));
     return sources[0];
   };
 }
 export function newOriginalSources(sourceInfo: Array<OriginalSourceData>) {
   return async ({ dispatch, getState }: ThunkArgs) => {
+    sourceInfo = sourceInfo.filter(({ id }) => !getSource(getState(), id));
+    sourceInfo = uniqBy(sourceInfo, ({ id }) => id);
+
     const sources: Array<Source> = sourceInfo.map(({ id, url }) => ({
       id,
       url,
       relativeUrl: url,
       isPrettyPrinted: false,
       isWasm: false,
       isBlackBoxed: false,
       introductionUrl: null,
--- a/devtools/client/debugger/src/actions/sources/tests/newSources.spec.js
+++ b/devtools/client/debugger/src/actions/sources/tests/newSources.spec.js
@@ -5,16 +5,17 @@
 // @flow
 
 import {
   actions,
   selectors,
   createStore,
   makeSource,
   makeSourceURL,
+  makeOriginalSource,
   waitForState,
 } from "../../../utils/test-head";
 const {
   getSource,
   getSourceCount,
   getSelectedSource,
   getSourceByURL,
 } = selectors;
@@ -30,17 +31,30 @@ describe("sources - new sources", () => 
 
     expect(getSourceCount(getState())).toEqual(2);
     const base = getSource(getState(), "base.js");
     const jquery = getSource(getState(), "jquery.js");
     expect(base && base.id).toEqual("base.js");
     expect(jquery && jquery.id).toEqual("jquery.js");
   });
 
-  it("should not add multiple identical sources", async () => {
+  it("should not add multiple identical generated sources", async () => {
+    const { dispatch, getState } = createStore(mockCommandClient);
+
+    const generated = await dispatch(
+      actions.newGeneratedSource(makeSource("base.js"))
+    );
+
+    await dispatch(actions.newOriginalSource(makeOriginalSource(generated)));
+    await dispatch(actions.newOriginalSource(makeOriginalSource(generated)));
+
+    expect(getSourceCount(getState())).toEqual(2);
+  });
+
+  it("should not add multiple identical original sources", async () => {
     const { dispatch, getState } = createStore(mockCommandClient);
 
     await dispatch(actions.newGeneratedSource(makeSource("base.js")));
     await dispatch(actions.newGeneratedSource(makeSource("base.js")));
 
     expect(getSourceCount(getState())).toEqual(1);
   });