Home Should I Ajax or should I store the whole collection into a variable ?
Reply: 2

Should I Ajax or should I store the whole collection into a variable ?

Alexandre Bourlier
1#
Alexandre Bourlier Published in 2017-12-07 14:46:34Z

I am building a single page app. The app has a list of 7000 ports stored in a MongoDB database. I need to be able to search for those ports with autocomplete on the search.

Should I Ajax the autocomplete results ?

OR

Should I retrieve the whole collection of ports, store it in a variable, plug my autocomplete on this array ?

What's the best practice ? What's the smartest performance wise ?

astalor
2#
astalor Reply to 2017-12-07 14:48:14Z

Best practice and smartest performance wise is to:

  1. Send the search string to an API resource, example:

    /autocomplete?search=portname1
    
  2. Retrieve the autocomplete results and visualize them

  3. You can use existing JS libraries for autocomplete (avoid discovering the hot water)
Crappy
3#
Crappy Reply to 2017-12-07 15:32:44Z

Because you said the list can grow I would not load the whole list into your app. This could lead to performance issues if your list becomes too big.

I would solve this problem in this way:

  1. Make a route on your webservice, which returns lets say the top 10-20 results matching your search.
  2. On input send a GET request to your endpoint.
  3. To improve performance you could cache the list in an in-memory database like Redis to avoid slow database-access on every request.
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.315556 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO