Skip to content

Commit bc6a72d

Browse files
committed
perf: implement log filtering cache and optimized table rendering
1 parent e5eb76f commit bc6a72d

3 files changed

Lines changed: 35 additions & 28 deletions

File tree

src/App.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -272,31 +272,42 @@ class App extends React.Component {
272272
});
273273
}
274274

275+
getFilteredLogs = () => {
276+
const { currentLogData, timeRange, filters, activeDatasetIndex } = this.state;
277+
if (!currentLogData || !currentLogData.tripLogs) return [];
278+
279+
const cacheKey = `${activeDatasetIndex}-${timeRange.minTime}-${timeRange.maxTime}-${JSON.stringify(filters)}`;
280+
281+
if (this._logsCache && this._logsCache.key === cacheKey) {
282+
return this._logsCache.logs;
283+
}
284+
285+
const logs = currentLogData.tripLogs
286+
.getLogs_(new Date(timeRange.minTime), new Date(timeRange.maxTime), filters)
287+
.value();
288+
289+
this._logsCache = { key: cacheKey, logs };
290+
return logs;
291+
};
292+
275293
selectFirstRow = () => {
276294
return new Promise((resolve) => {
277-
this.setState((prevState) => {
278-
const minDate = new Date(prevState.timeRange.minTime);
279-
const maxDate = new Date(prevState.timeRange.maxTime);
280-
const logs = this.state.currentLogData.tripLogs.getLogs_(minDate, maxDate, prevState.filters).value();
281-
if (logs.length > 0) {
282-
const firstRow = logs[0];
283-
setTimeout(() => this.focusOnSelectedRow(), 0);
295+
const logs = this.getFilteredLogs();
296+
if (logs.length > 0) {
297+
const firstRow = logs[0];
298+
this.setState({ featuredObject: firstRow }, () => {
299+
this.focusOnSelectedRow();
284300
resolve(firstRow);
285-
return { featuredObject: firstRow };
286-
} else {
287-
console.log("selectFirstRow: No logs found in the current time range");
288-
resolve(null);
289-
return null;
290-
}
291-
});
301+
});
302+
} else {
303+
console.log("selectFirstRow: No logs found in the current time range");
304+
resolve(null);
305+
}
292306
});
293307
};
294308

295309
selectLastRow = () => {
296-
const minDate = new Date(this.state.timeRange.minTime);
297-
const maxDate = new Date(this.state.timeRange.maxTime);
298-
const logsWrapper = this.state.currentLogData.tripLogs.getLogs_(minDate, maxDate, this.state.filters);
299-
const logs = logsWrapper.value();
310+
const logs = this.getFilteredLogs();
300311
if (logs.length > 0) {
301312
const lastRow = logs[logs.length - 1];
302313
this.setFeaturedObject(lastRow);
@@ -307,10 +318,8 @@ class App extends React.Component {
307318
};
308319

309320
handleRowChange = async (direction) => {
310-
const { featuredObject, filters } = this.state;
311-
const minDate = new Date(this.state.timeRange.minTime);
312-
const maxDate = new Date(this.state.timeRange.maxTime);
313-
const logs = this.state.currentLogData.tripLogs.getLogs_(minDate, maxDate, filters).value();
321+
const { featuredObject } = this.state;
322+
const logs = this.getFilteredLogs();
314323
let newFeaturedObject = featuredObject;
315324
const currentIndex = logs.findIndex((log) => log.timestamp === featuredObject.timestamp);
316325

@@ -920,9 +929,7 @@ class App extends React.Component {
920929

921930
setTimeout(() => {
922931
if (savedRowIndex >= 0) {
923-
const logs = tripLogs
924-
.getLogs_(new Date(this.state.timeRange.minTime), new Date(this.state.timeRange.maxTime))
925-
.value();
932+
const logs = this.getFilteredLogs();
926933

927934
if (savedRowIndex < logs.length) {
928935
log(`Restoring row at index ${savedRowIndex}`);

src/LogTable.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ function LogTable(props) {
165165
const [selectedRowIndex, setSelectedRowIndex] = useState(-1);
166166
const minTime = props.timeRange.minTime;
167167
const maxTime = props.timeRange.maxTime;
168-
const data = props.logData.tripLogs.getLogs_(new Date(minTime), new Date(maxTime), props.filters).value();
168+
const data = React.useMemo(() => {
169+
return props.logData.tripLogs.getLogs_(new Date(minTime), new Date(maxTime), props.filters).value();
170+
}, [props.logData.tripLogs, minTime, maxTime, props.filters]);
169171
const columnShortWidth = 50;
170172
const columnRegularWidth = 120;
171173
const columnLargeWidth = 150;

src/TripLogs.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,11 @@ class TripLogs {
303303
let rawLogsChain = this.getRawLogs_(minDate, maxDate);
304304

305305
if (logTypes && this.solutionType === "ODRD") {
306-
log("Applying ODRD log type filters.");
307306
rawLogsChain = rawLogsChain.filter((le) => logTypes[le["@type"]]);
308307
}
309308

310309
if (tripId && tripId.trim() !== "") {
311310
const trimmedFilter = tripId.trim();
312-
log(`Applying trip ID filter: "${trimmedFilter}"`);
313311
rawLogsChain = rawLogsChain.filter((le) => {
314312
// Check trip ID in trip rows
315313
const requestId = _.get(le, "request.tripid");

0 commit comments

Comments
 (0)