Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Reselect with Memoize #2042

Merged
merged 3 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/jaeger-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"redux-first-history": "^5.1.1",
"redux-form": "^8.3.10",
"redux-promise-middleware": "^6.1.3",
"reselect": "^4.1.6",
"store": "^2.0.12",
"ts-key-enum": "^2.0.0",
"tween-functions": "^1.2.0",
Expand Down
47 changes: 45 additions & 2 deletions packages/jaeger-ui/src/components/DependencyGraph/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import memoizeOne from 'memoize-one';

import DAG from './DAG';
import DependencyForceGraph from './DependencyForceGraph';
Expand All @@ -25,7 +26,6 @@
import * as jaegerApiActions from '../../actions/jaeger-api';
import { FALLBACK_DAG_MAX_NUM_SERVICES } from '../../constants';
import { nodesPropTypes, linksPropTypes } from '../../propTypes/dependencies';
import { formatDependenciesAsNodesAndLinks } from '../../selectors/dependencies';
import { getConfigValue } from '../../utils/config/get-config';

import './index.css';
Expand Down Expand Up @@ -128,13 +128,56 @@
}
}

const formatDependenciesAsNodesAndLinks = memoizeOne(dependencies => {
const data = dependencies.reduce(
(response, link) => {
const { nodeMap } = response;
let { links } = response;

// add both the parent and child to the node map, or increment their
// call count.
nodeMap[link.parent] = nodeMap[link.parent] ? nodeMap[link.parent] + link.callCount : link.callCount;
nodeMap[link.child] = nodeMap[link.child]
? response.nodeMap[link.child] + link.callCount

Check warning on line 141 in packages/jaeger-ui/src/components/DependencyGraph/index.jsx

View check run for this annotation

Codecov / codecov/patch

packages/jaeger-ui/src/components/DependencyGraph/index.jsx#L141

Added line #L141 was not covered by tests
: link.callCount;

// filter out self-dependent
if (link.parent !== link.child) {
links = links.concat([
{
source: link.parent,
target: link.child,
callCount: link.callCount,
value: Math.max(Math.sqrt(link.callCount / 10000), 1),
target_node_size: Math.max(Math.log(nodeMap[link.child] / 1000), 3),
},
]);
}

return { nodeMap, links };
},
{ nodeMap: {}, links: [] }
);

data.nodes = Object.keys(data.nodeMap).map(id => ({
callCount: data.nodeMap[id],
radius: Math.max(Math.log(data.nodeMap[id] / 1000), 3),
orphan: data.links.findIndex(link => id === link.source || id === link.target) === -1,
id,
}));

const { nodes, links } = data;

return { nodes, links };
});

// export for tests
export function mapStateToProps(state) {
const { dependencies, error, loading } = state.dependencies;
let links;
let nodes;
if (dependencies && dependencies.length > 0) {
const formatted = formatDependenciesAsNodesAndLinks({ dependencies });
const formatted = formatDependenciesAsNodesAndLinks(dependencies);
links = formatted.links;
nodes = formatted.nodes;
}
Expand Down
62 changes: 0 additions & 62 deletions packages/jaeger-ui/src/selectors/dependencies.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/jaeger-ui/tsconfig.lint.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"src/reducers/index.js",
"src/reducers/services.js",
"src/reducers/trace.js",
"src/selectors/dependencies.js",
"src/utils/configure-store.js",
"src/utils/sort.js",
"package.json"
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8943,11 +8943,6 @@ requires-port@^1.0.0:
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=

reselect@^4.1.6:
version "4.1.8"
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.1.8.tgz#3f5dc671ea168dccdeb3e141236f69f02eaec524"
integrity sha512-ab9EmR80F/zQTMNeneUr4cv+jSwPJgIlvEmVwLerwrWVbpLlBuls9XHzIeTFy4cegU2NHBp3va0LKOzU5qFEYQ==

resize-observer-polyfill@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
Expand Down
Loading