-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: decrease dashboard request response load size (#1596)
Request load improvements: * Limit the request that fetches all dashboards (for the dashboard bar) to only getting id, displayName, favorite~rename(starred). This reduces the response size from 3.9kb to 1.1kb on the SL database. Feels like a drop in the bucket, but that will have a bigger impact on instances with a lot of dashboards * Create separate requests getting a single dashboard for viewing and editing. In view, there are several fields that aren't used. In edit, we need all the fields if we are going to PUT changes. Refactor: * move getCustomDashboards to own module file * split up api requests for dashboards into separate files
- Loading branch information
1 parent
827f643
commit 9ac201f
Showing
16 changed files
with
172 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const deleteDashboardMutation = { | ||
type: 'delete', | ||
resource: 'dashboards', | ||
id: ({ id }) => id, | ||
} | ||
|
||
export const apiDeleteDashboard = async (dataEngine, id) => { | ||
try { | ||
await dataEngine.mutate(deleteDashboardMutation, { variables: { id } }) | ||
} catch (error) { | ||
console.log('Error: ', error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const dashboardsQuery = { | ||
resource: 'dashboards', | ||
params: { | ||
fields: ['id', 'displayName', 'favorite~rename(starred)'], | ||
paging: false, | ||
}, | ||
} | ||
|
||
export const apiFetchDashboards = async dataEngine => { | ||
try { | ||
const dashboardsData = await dataEngine.query({ | ||
dashboards: dashboardsQuery, | ||
}) | ||
|
||
return dashboardsData.dashboards.dashboards | ||
} catch (error) { | ||
console.log('Error: ', error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import arrayClean from 'd2-utilizr/lib/arrayClean' | ||
import { | ||
getIdNameFields, | ||
getListItemFields, | ||
getFavoritesFields, | ||
} from './metadata' | ||
import { isViewMode } from '../components/Dashboard/dashboardModes' | ||
|
||
const getDashboardItemsFields = () => | ||
arrayClean([ | ||
'id', | ||
'type', | ||
'shape', | ||
'x', | ||
'y', | ||
'width~rename(w)', | ||
'height~rename(h)', | ||
'messages', | ||
'text', | ||
'appKey', | ||
`${getListItemFields().join(',')}`, | ||
`${getFavoritesFields().join(',')}`, | ||
]) | ||
|
||
const baseDashboardFields = arrayClean([ | ||
'id', | ||
'displayName', | ||
'displayDescription', | ||
'favorite~rename(starred)', | ||
'access', | ||
'restrictFilters', | ||
'allowedFilters', | ||
`dashboardItems[${getDashboardItemsFields().join(',')}]`, | ||
]) | ||
|
||
export const viewDashboardQuery = { | ||
resource: 'dashboards', | ||
id: ({ id }) => id, | ||
params: { | ||
fields: baseDashboardFields, | ||
}, | ||
} | ||
|
||
export const editDashboardQuery = { | ||
resource: 'dashboards', | ||
id: ({ id }) => id, | ||
params: { | ||
fields: arrayClean([ | ||
...baseDashboardFields, | ||
`user[${getIdNameFields({ rename: true }).join(',')}]`, | ||
'name', | ||
'description', | ||
'created', | ||
'lastUpdated', | ||
'href', // needed for d2-ui-translations-dialog | ||
]), | ||
}, | ||
} | ||
|
||
// Get more info about selected dashboard | ||
export const apiFetchDashboard = async (dataEngine, id, mode) => { | ||
const query = isViewMode(mode) ? viewDashboardQuery : editDashboardQuery | ||
try { | ||
const dashboardData = await dataEngine.query( | ||
{ dashboard: query }, | ||
{ | ||
variables: { | ||
id, | ||
}, | ||
} | ||
) | ||
|
||
return dashboardData.dashboard | ||
} catch (error) { | ||
console.log('Error: ', error) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.