Open rattanakchea opened 8 years ago
It is possible to use this on the client side, it's all just vanilla JS. However, the codes file is a little over 4MB in size, which might be a little large to send out to the client. It shouldn't be that hard to use this module via XHR, which is how I would use it.
I am trying to speed up the query by reducing round trip to server. But I guess the slow query comes from this function.
//This is SLLOOOOWWWWW
exports.radius = function(zip, miles, full) {
var ret = [], i, d;
for (i in codes.codes) {
if (dist(zip, i) <= miles) {
ret.push(((full) ? codes.codes[i] : i));
}
}
return ret;
};
When I use query the radius, it takes a good 5-8 seconds to retrieve data. What are some ways to improve this performance? Using a database?
Yeah, if you need to query the distance then you're best bet will be to put the data into a DB that you can limit the queries with some processing. This module does it all in memory so it walks the entire structure on each lookup. You might be able to come up with a smaller way to store the data so the lookups are much quicker.
Honestly, you can just ship it out browserified. The codes database uncompressed is 4 meg, which is smaller than most youtube videos, and then you can use it locally as a datastructure.
Memory footprint might be too much for phones.
I added a /zipCodes route to the node server we were using to serve the react client code to do the zip code lookup and returned the response to the client.
On a client, I want to check the distance between two zip codes. What are some approaches to accomplish that with this module since this is a server side node module ?