Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.
Imani edited this page Sep 12, 2017 · 5 revisions

Ligo - Wiki

In this wiki I keep track of all the problems I encountered and what I did to solve them.

MongoDB Many-to-Many & Lazy loading

One of the critea for this assignment is to avoid Lazy Loading (N + 1). I am pretty much new to MongoDB and I'm aware that joins aren't available in MongoDB. To retrieve all referenced data with sothe Sails/Waterline query language you can use .populate(). I'm still not sure what happens and I can't really find it but looking at the results from the blueprint API I'm almost sure populate is a form of lazy loading I'll have to ask but I shouldn't break my head over it right now.

This question hints that .populate() uses a lazy loading technique. https://stackoverflow.com/questions/31490663/effectively-using-association-population-in-sailsjs

This more recent talk shows that using .populate() is fine and avoids the (N + 1) problem https://www.youtube.com/watch?v=F7DibDrqrjw&feature=youtu.be&t=8m57s (The talk is not too optimistic about the waterline ORM though)

"The most common performance bottleneck in production Sails applications is the database. Over the lifetime of an application with a growing user base, it becomes increasingly important to set up good indexes on your tables/collections, and to use queries which return paginated results. Eventually as your production database grows to contain tens of millions of records, you will start to locate and optimize slow queries by hand (either by calling .query() or .native(), or by using the underlying database driver from NPM)."

"Currently Waterline doesn't support multi-column indexes in the attributes definition. If you would like to build any sort of special index you will still need to build that manually. Also note that when adding a unique property to an attribute, an index will automatically be created for that attribute.

There is currently an issue with adding indexes to string fields. Because Waterline performs its queries in a case insensitive manner, we are unable to use the index on a string attribute. There are some workarounds being discussed but nothing is implemented so far. This will be updated in the near future to fully support indexes on strings."

Clone this wiki locally