Skip to content

Commit

Permalink
fixing concurrency issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Feb 25, 2021
1 parent b89f4a1 commit 33308e3
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
});

const { pageIndex, sort } = tableOptions;
const { direction, field } = sort;

const { transactionType } = useApmServiceContext();
const {
Expand Down Expand Up @@ -96,12 +97,13 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
},
}).then((response) => {
return {
// Used to refetch the comparison statistics when a new primary statistics were fetched.
// Everytime the primary statistics is refetched, updates the requestId making the comparison API to be refetched.
requestId: uuid(),
...response,
};
});
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[
environment,
kuery,
Expand All @@ -110,14 +112,18 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
end,
transactionType,
latencyAggregationType,
comparisonType,
pageIndex,
direction,
field,
]
);

const { transactionGroups, requestId } = data;
const currentPageTransactionGroups = orderBy(
transactionGroups,
sort.field,
sort.direction
field,
direction
).slice(pageIndex * PAGE_SIZE, (pageIndex + 1) * PAGE_SIZE);

const transactionNames = JSON.stringify(
Expand Down Expand Up @@ -158,12 +164,9 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
});
}
},
// only fetches statistics when requestId, transaction names or comparison type change
// requestId: Is used to refetch the comparison data when a new primary statistics were fetched.
// transactionNams: Is used to fetch the comparison data when a user navigate to a different page within the table
// comparison type: Is used to refetch the comparison when the comparison type is changed, either manually by a user or automatically when the date picker is changed
// only fetches comparison statistics when requestId is invalidated by primary statistics api call
// eslint-disable-next-line react-hooks/exhaustive-deps
[requestId, transactionNames, comparisonType],
[requestId],
{ preservePreviousData: false }
);

Expand All @@ -185,13 +188,6 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
hidePerPageOptions: true,
};

const sorting = {
sort: {
field: sort.field,
direction: sort.direction,
},
};

return (
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>
Expand Down Expand Up @@ -234,7 +230,7 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
items={currentPageTransactionGroups}
columns={columns}
pagination={pagination}
sorting={sorting}
sorting={{ sort: { field, direction } }}
onChange={(newTableOptions: {
page?: {
index: number;
Expand Down

0 comments on commit 33308e3

Please sign in to comment.