-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically sort samples query results by importDate (#152)
* Prevent SamplesList from being re-rendered needlessly The previous implementation of refetchWhereVariables in SamplesPage was causing double rendering because it was defined inline within the SamplesList component's props. This meant that this function was re-created on every render of SamplesPage. Since SamplesList uses this function in a useEffect hook's dependency array, each time SamplesPage rendered, it triggered the useEffect in SamplesList to run again, causing an additional render. * Sort samples query result by import date * Implement DataLoader to prevent the samples query from calling the db 2x
- Loading branch information
Showing
8 changed files
with
109 additions
and
56 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { OGM } from "@neo4j/graphql-ogm"; | ||
import { includeCancerTypeFieldsInSearch } from "./oncotree"; | ||
import { querySamplesList } from "./ogm"; | ||
import DataLoader from "dataloader"; | ||
import { SamplesListQuery, SampleWhere } from "../generated/graphql"; | ||
import NodeCache from "node-cache"; | ||
|
||
type SamplesQueryResult = { | ||
totalCount: number; | ||
data: SamplesListQuery["samples"]; | ||
}; | ||
|
||
/** | ||
* Create a DataLoader instance that batches the child queries (e.g. `samples` and | ||
* `samplesConnection` child queries of SamplesList query) and then caches the results | ||
* of those child queries within the same frontend request. | ||
* | ||
* This enables the SamplesList query to make a single trip to the database. | ||
* Without this, we would make two trips, one via the `samples` child query and one | ||
* via the `samplesConnection` child query. | ||
*/ | ||
export function createSamplesLoader(ogm: OGM, oncotreeCache: NodeCache) { | ||
return new DataLoader<SampleWhere, SamplesQueryResult>(async (keys) => { | ||
const customWhere = includeCancerTypeFieldsInSearch(keys[0], oncotreeCache); | ||
const result = await querySamplesList(ogm, customWhere); | ||
return keys.map(() => result); | ||
}); | ||
} |
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