Skip to content

Commit

Permalink
fix: speed up search
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Apr 24, 2021
1 parent ed2fd70 commit 337b0a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 3 additions & 2 deletions components/ResidentIdSearchbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const ResidentIdSearchbar = ({ surveyee, setSurveyee, surveyingOrganization }) =
}, [surveyingOrganization]);

const fetchOfflineData = async () => {
setLoading(true);
setOnline(false);

getData('residentData').then((residentData) => {
Expand All @@ -46,7 +45,6 @@ const ResidentIdSearchbar = ({ surveyee, setSurveyee, surveyingOrganization }) =
};

const fetchOnlineData = async (qry) => {
setLoading(true);
setOnline(true);

const records = await parseSearch(surveyingOrganization, qry);
Expand Down Expand Up @@ -91,6 +89,9 @@ const ResidentIdSearchbar = ({ surveyee, setSurveyee, surveyingOrganization }) =

const onChangeSearch = (input) => {
setLoading(true);

if (input === '') setLoading(false);

clearTimeout(searchTimeout);

setQuery(input);
Expand Down
10 changes: 3 additions & 7 deletions components/ResidentIdSearchbar/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ const parseSearch = (surveyingOrganization, qry) => {
}

const fname = new Parse.Query('SurveyData');
fname.limit(2000);
fname.limit(1000);
fname.startsWith('fname', qry);

const lname = new Parse.Query('SurveyData');
lname.limit(2000);
lname.limit(1000);
lname.startsWith('lname', qry);

const nname = new Parse.Query('SurveyData');
nname.limit(2000);
nname.startsWith('nickname', qry);

return new Promise((resolve, reject) => {
const query = Parse.Query.or(fname, lname, nname);
const query = Parse.Query.or(fname, lname);

query.descending('createdAt');

Expand Down

0 comments on commit 337b0a8

Please sign in to comment.