-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: duration & endtime in queries history #1169
Changes from 3 commits
d936243
0b1ad4d
bca3ec8
25f1deb
7c277a9
48a5ad9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ const MAXIMUM_QUERIES_IN_HISTORY = 20; | |
|
||
const CHANGE_USER_INPUT = 'query/CHANGE_USER_INPUT'; | ||
const SAVE_QUERY_TO_HISTORY = 'query/SAVE_QUERY_TO_HISTORY'; | ||
const UPDATE_QUERY_IN_HISTORY = 'query/UPDATE_QUERY_IN_HISTORY'; | ||
const SET_QUERY_HISTORY_FILTER = 'query/SET_QUERY_HISTORY_FILTER'; | ||
const GO_TO_PREVIOUS_QUERY = 'query/GO_TO_PREVIOUS_QUERY'; | ||
const GO_TO_NEXT_QUERY = 'query/GO_TO_NEXT_QUERY'; | ||
|
@@ -65,9 +66,9 @@ const executeQuery: Reducer<ExecuteQueryState, ExecuteQueryAction> = ( | |
} | ||
|
||
case SAVE_QUERY_TO_HISTORY: { | ||
const queryText = action.data; | ||
const {queryText, queryId} = action.data; | ||
|
||
const newQueries = [...state.history.queries, {queryText}].slice( | ||
const newQueries = [...state.history.queries, {queryText, queryId}].slice( | ||
state.history.queries.length >= MAXIMUM_QUERIES_IN_HISTORY ? 1 : 0, | ||
); | ||
settingsManager.setUserSettingsValue(QUERIES_HISTORY_KEY, newQueries); | ||
|
@@ -82,6 +83,38 @@ const executeQuery: Reducer<ExecuteQueryState, ExecuteQueryAction> = ( | |
}; | ||
} | ||
|
||
case UPDATE_QUERY_IN_HISTORY: { | ||
const {queryId, stats} = action.data; | ||
|
||
if (!stats) { | ||
return state; | ||
} | ||
|
||
const index = state.history.queries.findIndex((item) => item.queryId === queryId); | ||
|
||
if (index === -1) { | ||
return state; | ||
} | ||
|
||
const newQueries = [...state.history.queries]; | ||
const {duration, endTime} = stats; | ||
newQueries.splice(index, 1, { | ||
...state.history.queries[index], | ||
duration, | ||
endTime, | ||
}); | ||
|
||
settingsManager.setUserSettingsValue(QUERIES_HISTORY_KEY, newQueries); | ||
|
||
return { | ||
...state, | ||
history: { | ||
...state.history, | ||
queries: newQueries, | ||
}, | ||
}; | ||
} | ||
|
||
case GO_TO_PREVIOUS_QUERY: { | ||
const currentIndex = state.history.currentIndex; | ||
if (currentIndex <= 0) { | ||
|
@@ -150,6 +183,11 @@ interface SendQueryParams extends QueryRequestParams { | |
enableTracingLevel?: boolean; | ||
} | ||
|
||
interface QueryStats { | ||
duration?: string | number; | ||
endTime?: string | number; | ||
} | ||
|
||
export const executeQueryApi = api.injectEndpoints({ | ||
endpoints: (build) => ({ | ||
executeQuery: build.mutation<IQueryResult, SendQueryParams>({ | ||
|
@@ -162,7 +200,7 @@ export const executeQueryApi = api.injectEndpoints({ | |
enableTracingLevel, | ||
queryId, | ||
}, | ||
{signal}, | ||
{signal, dispatch}, | ||
) => { | ||
let action: ExecuteActions = 'execute'; | ||
let syntax: QuerySyntax = QUERY_SYNTAX.yql; | ||
|
@@ -175,6 +213,7 @@ export const executeQueryApi = api.injectEndpoints({ | |
} | ||
|
||
try { | ||
const timeStart = Date.now(); | ||
const response = await window.api.sendQuery( | ||
{ | ||
schema, | ||
|
@@ -201,6 +240,19 @@ export const executeQueryApi = api.injectEndpoints({ | |
} | ||
|
||
const data = parseQueryAPIExecuteResponse(response); | ||
|
||
const queryStats: QueryStats = {}; | ||
if (data.stats) { | ||
const {DurationUs, Executions: [{FinishTimeMs}] = [{}]} = data.stats; | ||
queryStats.duration = DurationUs; | ||
queryStats.endTime = FinishTimeMs; | ||
} else { | ||
const now = Date.now(); | ||
queryStats.duration = (now - timeStart) * 1000; | ||
queryStats.endTime = now; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about saving duration as In both cases I suggest adding metric to field name: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I keep existing format from api. we could replace |
||
} | ||
|
||
dispatch(updateQueryInHistory(queryStats, queryId)); | ||
return {data}; | ||
} catch (error) { | ||
return {error}; | ||
|
@@ -211,13 +263,20 @@ export const executeQueryApi = api.injectEndpoints({ | |
overrideExisting: 'throw', | ||
}); | ||
|
||
export const saveQueryToHistory = (queryText: string) => { | ||
export const saveQueryToHistory = (queryText: string, queryId: string) => { | ||
return { | ||
type: SAVE_QUERY_TO_HISTORY, | ||
data: queryText, | ||
data: {queryText, queryId}, | ||
} as const; | ||
}; | ||
|
||
export function updateQueryInHistory(stats: QueryStats, queryId: string) { | ||
return { | ||
type: UPDATE_QUERY_IN_HISTORY, | ||
data: {queryId, stats}, | ||
} as const; | ||
} | ||
|
||
export const goToPreviousQuery = () => { | ||
return { | ||
type: GO_TO_PREVIOUS_QUERY, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
row.endTime.toString()
instead ofrow.endTime as string
, it more error proof