Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid using _.each on set method #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

avoid using _.each on set method #30

wants to merge 1 commit into from

Conversation

wellingguzman
Copy link

@wellingguzman wellingguzman commented Jun 16, 2017

Models with an attribute named 'length' will make this each work as an array.

From underscore docs

Note: Collection functions work on arrays, objects, and array-like objects such as arguments, NodeList and similar. But it works by duck-typing, so avoid passing objects with a numeric length property. It's also good to note that an each loop cannot be broken out of — to break, use _.find instead.


I do not check for hasOwnProperty in the for statement in the new code because it's not done in Backbone either so, just to keep things the same.

Explanation:

We have been using trackit for a while with Directus. We used to have a weird bug that we weren't able to reproduce, after a long research and testing we find out the problem was _.each, we have models that represents columns, a column can have a length but when we use columns with small length number 10, 100, 255, this wasn't noticeable, then we started using MEDIUMTEXT and LONGTEXT which translate to a 16,777,215 and 4,294,967,295 which takes time to process an array of that length, blocking the page from a couple of seconds to minutes.

Models with an attributed named 'length' will make this each work as an array unexpectedly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant