Skip to content

Commit

Permalink
Merge pull request jaegertracing#353 from rubenvp8510/Issue-344
Browse files Browse the repository at this point in the history
Use memoize-one instead of bespoke solutions
Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
  • Loading branch information
everett980 authored Mar 25, 2019
2 parents 756f157 + ff242b0 commit f5b02ac
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 155 deletions.
1 change: 1 addition & 0 deletions packages/jaeger-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"json-markup": "^1.1.0",
"lodash": "^4.17.4",
"logfmt": "^1.2.0",
"memoize-one": "^5.0.0",
"moment": "^2.18.1",
"prop-types": "^15.5.10",
"query-string": "^5.0.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/jaeger-ui/src/components/SearchTracePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import queryString from 'query-string';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import store from 'store';
import memoizeOne from 'memoize-one';

import SearchForm from './SearchForm';
import SearchResults, { sortFormSelector } from './SearchResults';
Expand All @@ -33,7 +34,6 @@ import { getLocation as getTraceLocation } from '../TracePage/url';
import { actions as traceDiffActions } from '../TraceDiff/duck';
import { fetchedState } from '../../constants';
import { sortTraces } from '../../model/search';
import getLastXformCacher from '../../utils/get-last-xform-cacher';
import { stripEmbeddedState } from '../../utils/embedded-url';
import FileLoader from './FileLoader';

Expand Down Expand Up @@ -191,7 +191,7 @@ SearchTracePageImpl.propTypes = {
loadJsonTraces: PropTypes.func,
};

const stateTraceXformer = getLastXformCacher(stateTrace => {
const stateTraceXformer = memoizeOne(stateTrace => {
const { traces: traceMap, search } = stateTrace;
const { query, results, state, error: traceError } = search;

Expand All @@ -201,19 +201,19 @@ const stateTraceXformer = getLastXformCacher(stateTrace => {
return { traces, maxDuration, traceError, loadingTraces, query };
});

const stateTraceDiffXformer = getLastXformCacher((stateTrace, stateTraceDiff) => {
const stateTraceDiffXformer = memoizeOne((stateTrace, stateTraceDiff) => {
const { traces } = stateTrace;
const { cohort } = stateTraceDiff;
return cohort.map(id => traces[id] || { id });
});

const sortedTracesXformer = getLastXformCacher((traces, sortBy) => {
const sortedTracesXformer = memoizeOne((traces, sortBy) => {
const traceResults = traces.slice();
sortTraces(traceResults, sortBy);
return traceResults;
});

const stateServicesXformer = getLastXformCacher(stateServices => {
const stateServicesXformer = memoizeOne(stateServices => {
const {
loading: loadingServices,
services: serviceList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import _get from 'lodash/get';
import _map from 'lodash/map';
import memoizeOne from 'memoize-one';

import convPlexus from '../../../model/trace-dag/convPlexus';
import TraceDag from '../../../model/trace-dag/TraceDag';
Expand All @@ -24,41 +25,20 @@ import type { Trace } from '../../../types/trace';

export type TVertexKeys = Set<number | string>;

let lastUiFind: string;
let lastVertices: PVertex<Trace>[];
let uiFindVertexKeys: ?TVertexKeys;

export function getUiFindVertexKeys(uiFind: string, vertices: PVertex<Trace>[]): TVertexKeys {
export const getUiFindVertexKeys = memoizeOne((uiFind: string, vertices: PVertex<Trace>[]): TVertexKeys => {
if (!uiFind) return new Set();
if (uiFind === lastUiFind && vertices === lastVertices && uiFindVertexKeys) {
return uiFindVertexKeys;
}
const newVertexKeys: Set<number | string> = new Set();
vertices.forEach(({ key, data: { members } }) => {
if (_get(filterSpans(uiFind, _map(members, 'span')), 'size')) {
newVertexKeys.add(key);
}
});
lastUiFind = uiFind;
lastVertices = vertices;
uiFindVertexKeys = newVertexKeys;
return newVertexKeys;
}

let lastAData: ?Trace;
let lastBData: ?Trace;
// TODO: use convPlexus type (everett JAG-343)
let edgesAndVertices: ?Object;
});

export function getEdgesAndVertices(aData: Trace, bData: Trace) {
if (aData === lastAData && bData === lastBData && edgesAndVertices) {
return edgesAndVertices;
}
lastAData = aData;
lastBData = bData;
export const getEdgesAndVertices = memoizeOne((aData: Trace, bData: Trace) => {
const aTraceDag = TraceDag.newFromTrace(aData);
const bTraceDag = TraceDag.newFromTrace(bData);
const diffDag = TraceDag.diff(aTraceDag, bTraceDag);
edgesAndVertices = convPlexus(diffDag.nodesMap);
return edgesAndVertices;
}
return convPlexus(diffDag.nodesMap);
});
41 changes: 0 additions & 41 deletions packages/jaeger-ui/src/utils/get-last-xform-cacher.js

This file was deleted.

83 changes: 0 additions & 83 deletions packages/jaeger-ui/src/utils/get-last-xform-cacher.test.js

This file was deleted.

6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7773,6 +7773,7 @@ lodash.uniq@^4.5.0:
lodash@4.17.11, lodash@4.x, "lodash@>=3.5 <5", lodash@^3.10.0, lodash@^4.15.0, lodash@^4.16.5, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1:
version "4.17.11"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==

logfmt@^1.2.0:
version "1.2.1"
Expand Down Expand Up @@ -7924,6 +7925,11 @@ mem@^4.0.0:
mimic-fn "^1.0.0"
p-is-promise "^2.0.0"

memoize-one@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.0.0.tgz#d55007dffefb8de7546659a1722a5d42e128286e"
integrity sha512-7g0+ejkOaI9w5x6LvQwmj68kUj6rxROywPSCqmclG/HBacmFnZqhVscQ8kovkn9FBCNJmOz6SY42+jnvZzDWdw==

memory-fs@^0.4.0, memory-fs@^0.4.1, memory-fs@~0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
Expand Down

0 comments on commit f5b02ac

Please sign in to comment.