-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Foundations for Warnings System (#161)
Currently, a staged place stores only the "original values" which come from the user. When code wants the corresponding "formatted value" for that propertly, it uses the validation library to format it on demand. When importing large CSV lists of CHUs/CHPs (like the Narok dataset), this results in >300,000 calls of Validation.formatSingle. This isn't that slow; but it slowed down a lot when we started autogenerating properties #47. The work happening in #20 requires more formatted of property data. Although the performance gains from this change aren't huge (below), I view these changes as a required foundation for that work lest things get even slower. This change therefore validates and formats the inputs once. The result is persisted as an IPropertyValue which contains .formatted and .original values. This adds complexity in the place datamodel, but simplifies upstream classes like RemotePlaceResolver. The interface to the Validation library has changed significantly. New interface is to create a new ValidatedPropertyValue(). Remote Place Caching Currently, the ChtApi.getPlacesWithType downloads all documents of a particular type and caches a subset of the data (id, name, lineage) as a RemotePlace. The warning system is going to need more data about these places so we can check for uniqueness (eg. unique facility codes). The doc's name information should also now be stored as "Property Value" and so this resulted in a reduced role of ChtApi (just fetches docs now), an increased role for RemotePlaceCache (it maps the doc down to a reduced set for caching), and a bit more complexity in Config. Performance Measures For Narok upload performance set (1640 CHPs) Before: 1170ms After: 601ms
- Loading branch information
1 parent
846b8bf
commit 90ef80d
Showing
54 changed files
with
1,480 additions
and
1,022 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,52 @@ | ||
import { Config, ContactType } from '../config'; | ||
import SessionCache from '../services/session-cache'; | ||
import { stringify } from 'csv/sync'; | ||
|
||
type File = { | ||
filename: string; | ||
content: string; | ||
}; | ||
|
||
export default function getCredentialsFiles(sessionCache: SessionCache, contactTypes: ContactType[]): File[] { | ||
const files: File[] = []; | ||
for (const contactType of contactTypes) { | ||
const places = sessionCache.getPlaces({ type: contactType.name }); | ||
if (!places.length) { | ||
continue; | ||
} | ||
|
||
const rows = places.map((place) => [ | ||
...Object.values(place.hierarchyProperties).map(prop => prop.formatted), | ||
place.name, | ||
place.contact.properties.name?.formatted, | ||
place.contact.properties.phone?.formatted, | ||
place.userRoles.join(' '), | ||
place.creationDetails.username, | ||
place.creationDetails.password, | ||
]); | ||
|
||
const constraints = Config.getHierarchyWithReplacement(contactType); | ||
const props = Object.keys(places[0].hierarchyProperties) | ||
.map(prop => constraints.find(c => c.property_name === prop)!.friendly_name); | ||
const columns = [ | ||
...props, | ||
contactType.friendly, | ||
'name', | ||
'phone', | ||
'role', | ||
'username', | ||
'password', | ||
]; | ||
|
||
const content = stringify(rows, { | ||
columns, | ||
header: true, | ||
}); | ||
files.push({ | ||
filename: `${contactType.name}.csv`, | ||
content, | ||
}); | ||
} | ||
|
||
return files; | ||
} |
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.