-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#898 | getUnderlyingRealmCollection directly instead of asArray since…
… it slows down sort by realm works differently from lodash. Lodash case-insensitive sorting done when custom filters need to be applied. Else the previous realm sorting behaviour is retained.
- Loading branch information
1 parent
51605f5
commit 8a39a26
Showing
1 changed file
with
11 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import PrivilegeService from "./PrivilegeService"; | |
import EntityApprovalStatusService from "./EntityApprovalStatusService"; | ||
import GroupSubjectService from "./GroupSubjectService"; | ||
import OrganisationConfigService from './OrganisationConfigService'; | ||
import {getUnderlyingRealmCollection} from "openchs-models"; | ||
|
||
@Service("individualService") | ||
class IndividualService extends BaseService { | ||
|
@@ -52,10 +53,11 @@ class IndividualService extends BaseService { | |
let searchResults, finalSearchResults = []; | ||
|
||
if (_.isEmpty(filterCriteria)) { | ||
searchResults = this.db.objects(Individual.schema.name); | ||
finalSearchResults = _.concat(finalSearchResults, searchResults.asArray()); | ||
searchResults = this.db.objects(Individual.schema.name).sorted("name"); | ||
finalSearchResults = getUnderlyingRealmCollection(searchResults); | ||
} else { | ||
function filterIndividualsByChunks(baseResult) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
// if chunkSize is less/more than 500, processing is slower | ||
const chunkSize = 500, noOfChunks = individualUUIDs.length / chunkSize; | ||
for (let chunk = 0; chunk < noOfChunks; chunk++) { | ||
let individualUuidsChunk = _.slice(individualUUIDs, chunk * chunkSize, ((chunk + 1) * chunkSize) - 1); | ||
|
@@ -71,13 +73,17 @@ class IndividualService extends BaseService { | |
filterCriteria, | ||
criteria.getMinDateOfBirth(), | ||
criteria.getMaxDateOfBirth() | ||
); | ||
).sorted("name"); | ||
|
||
_.isEmpty(individualUUIDs) ? finalSearchResults = _.concat(finalSearchResults, baseResult.asArray()) : | ||
if(_.isEmpty(individualUUIDs)) | ||
finalSearchResults = getUnderlyingRealmCollection(baseResult); | ||
else { | ||
filterIndividualsByChunks(baseResult); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
finalSearchResults = _.orderBy(finalSearchResults, [individual => individual.name.toLowerCase()]); | ||
This comment has been minimized.
Sorry, something went wrong.
himeshr
Contributor
|
||
} | ||
} | ||
|
||
return _.sortBy(finalSearchResults, ['name']); | ||
return finalSearchResults; | ||
} | ||
|
||
register(individual, nextScheduledVisits, skipCreatingPendingStatus, groupSubjectObservations) { | ||
|
Move this method out, to enable its reuse in future