Skip to content

Commit

Permalink
removed extra query call
Browse files Browse the repository at this point in the history
  • Loading branch information
Koustavd18 committed Nov 13, 2024
1 parent e0e26fc commit 849c5bb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@
"pretty-quick": "^3.1.3",
"typescript": "^5.1.6",
"vite": "^4.3.9"
}
},
"packageManager": "[email protected]+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee"
}
10 changes: 2 additions & 8 deletions src/pages/Stream/Views/Explore/LogsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import LogTable from './StaticLogTable';
import useLogsFetcher from './useLogsFetcher';
import LogsViewConfig from './LogsViewConfig';
import _ from 'lodash';
import { getOffset } from '@/utils';

import { useEffect } from 'react';

const { setPageAndPageData, setTargetPage, setTargetColumns, setDisabledColumns, setCurrentOffset } = logsStoreReducers;
const { setPageAndPageData, setTargetPage, setTargetColumns, setDisabledColumns } = logsStoreReducers;

const LogsView = (props: { schemaLoading: boolean; infoLoading: boolean }) => {
const { schemaLoading, infoLoading } = props;
Expand All @@ -19,7 +18,7 @@ const LogsView = (props: { schemaLoading: boolean; infoLoading: boolean }) => {
});

const [tableOpts] = useLogsStore((store) => store.tableOpts);
const { currentPage, targetPage, headers, targetColumns, perPage } = tableOpts;
const { currentPage, targetPage, headers, targetColumns } = tableOpts;
const [viewMode, setLogsStore] = useLogsStore((store) => store.viewMode);
const viewOpts = {
errorMessage,
Expand All @@ -32,11 +31,6 @@ const LogsView = (props: { schemaLoading: boolean; infoLoading: boolean }) => {
useEffect(() => {
if (!showTable) return;
if (targetPage) {
const offset = getOffset(targetPage, perPage);
if (offset > 0) {
setLogsStore((store) => setCurrentOffset(store, offset));
setLogsStore((store) => setTargetPage(store, targetPage - Math.ceil(offset / perPage)));
}
setLogsStore((store) => setPageAndPageData(store, targetPage));
if (currentPage === targetPage) {
setLogsStore((store) => setTargetPage(store, undefined));
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Stream/Views/Explore/useLogsFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const useLogsFetcher = (props: { schemaLoading: boolean; infoLoading: boolean })
useEffect(() => {
if (infoLoading) return;

if (currentPage === 0 && currentOffset === 0) {
if (currentPage === 0) {
getQueryData();
refetchCount();
}
Expand Down
25 changes: 16 additions & 9 deletions src/pages/Stream/hooks/useParamsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ import timeRangeUtils from '@/utils/timeRangeUtils';
import moment from 'moment-timezone';
import { filterStoreReducers, QueryType, useFilterStore } from '../providers/FilterProvider';
import { generateQueryBuilderASTFromSQL } from '../utils';
import { joinOrSplit } from '@/utils';
import { getOffset, joinOrSplit } from '@/utils';

const { getRelativeStartAndEndDate, formatDateWithTimezone, getLocalTimezone } = timeRangeUtils;
const { setTimeRange, onToggleView, setPerPage, setCustQuerySearchState, setTargetPage, setTargetColumns } =
logsStoreReducers;
const {
setTimeRange,
onToggleView,
setPerPage,
setCustQuerySearchState,
setTargetPage,
setCurrentOffset,
setTargetColumns,
} = logsStoreReducers;
const { applySavedFilters } = filterStoreReducers;
const timeRangeFormat = 'DD-MMM-YYYY_HH-mmz';
const keys = ['view', 'rows', 'page', 'interval', 'from', 'to', 'query', 'filterType', 'fields'];
Expand Down Expand Up @@ -55,19 +62,17 @@ const deriveTimeRangeParams = (timerange: TimeRange): { interval: string } | { f
const storeToParamsObj = (opts: {
timeRange: TimeRange;
view: string;
offset: string;
page: string;
rows: string;
query: string;
filterType: string;
fields: string;
}): Record<string, string> => {
const { timeRange, offset, page, view, rows, query, filterType, fields } = opts;
const { timeRange, page, view, rows, query, filterType, fields } = opts;

const params: Record<string, string> = {
...deriveTimeRangeParams(timeRange),
view,
offset,
rows,
page,
query,
Expand Down Expand Up @@ -107,7 +112,6 @@ const useParamsController = () => {
useEffect(() => {
const storeAsParams = storeToParamsObj({
timeRange,
offset: `${currentOffset}`,
page: `${targetPage ? targetPage : Math.ceil(currentPage + pageOffset)}`,
view: viewMode,
rows: `${perPage}`,
Expand All @@ -125,6 +129,11 @@ const useParamsController = () => {

if (storeAsParams.page !== presentParams.page) {
setLogsStore((store) => setTargetPage(store, _.toNumber(presentParams.page)));
const offset = getOffset(_.toNumber(presentParams.page), perPage);
if (offset > 0) {
setLogsStore((store) => setCurrentOffset(store, offset));
setLogsStore((store) => setTargetPage(store, _.toNumber(presentParams.page) - Math.ceil(offset / perPage)));
}
}

if (storeAsParams.query !== presentParams.query) {
Expand All @@ -146,7 +155,6 @@ const useParamsController = () => {
if (isStoreSynced) {
const storeAsParams = storeToParamsObj({
timeRange,
offset: `${currentOffset}`,
page: `${targetPage ? targetPage : Math.ceil(currentPage + pageOffset)}`,
view: viewMode,
rows: `${perPage}`,
Expand All @@ -165,7 +173,6 @@ const useParamsController = () => {

const storeAsParams = storeToParamsObj({
timeRange,
offset: `${currentOffset}`,
page: `${targetPage ? targetPage : Math.ceil(currentPage + pageOffset)}`,
view: viewMode,
rows: `${perPage}`,
Expand Down

0 comments on commit 849c5bb

Please sign in to comment.