-
Notifications
You must be signed in to change notification settings - Fork 547
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
Fix vector magnitude caching #142
Conversation
A typo in `Vector.magnitude()` was preventing it from returning the cached value
Fancy adding a test to prevent this from happening again? |
Not sure how I'd write a test for this since the method returns the correct value. I guess you could compare execution time between the first and subsequent calls, but that seems fragile. |
I guess that its output isn't covered by any of the existing tests is the problem. |
I think it's covered here: https://github.com/olivernn/lunr.js/blob/master/test/vector_test.js#L3 |
Ah yes, but not the caching. Oh well! I'll go back to sleep now 😴 |
I saw that yesterday as well, but also noticed another thing: The Maybe that's ok, since Vectors seem to be mostly one-use, but in cases where they might not be, the typo actually prevents stale cache issues. |
Thanks @satchmorun. I've added cache invalidation to |
Tpying is hrd! Good spot, wish there was a better way to prevent my fat fingered mashing of the keyboard resulting in bugs like this, any ideas? https://www.youtube.com/watch?v=OqjF7HKSaaI I've released version 0.5.8 with this change in, let me know if there are any issues, and thanks again for the pr. |
Haha, easily done. Caching code isn't exactly easy to test. :) We could try something like this (not tested):
However it doesn't prevent typos in the invalidation code (e.g. |
A typo in
Vector.magnitude()
was preventing it from returning the cached value