updateAttributes on jugglingdb-redis breaks index for non-string fields
- Vorherrschende Sprache
- JavaScript
- Sterne
- 2k
- Forks
- 238
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Thank you for all your hard work. I ran into an issue with the jugglingdb-redis adapter. I have several fields that are defined such as:
``` javascript
status: { type: Number, default: 1, index: true }
```
When I create an instance of the object with that field it saves fine and I can see in the store that there is an index created. However if I call updateAttributes on the same instance later the index actually disappears. I've debugged this and traced it back to the following code: [redis.js Line291](https://github.com/jugglingdb/redis-adapter/blob/master/lib/redis.js#L291). It compares the value being saved with the previous value and if they are different it adds the new one and removes the old one. The problem is it uses a !== for comparison so even though you could be passing the same value it will be removed if it is a number, or date or anything but a string. All keys and values in `prevData` are strings because they come from the hash that was retrieved with a `hgetall` at line 260. So when you try to do a `findOne` later on `status` it fails because it was removed from the index.
Let me know if this makes sense. I'd love to have this working so that I can use numbers, booleans, etc. and still search on them even after updating the records.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
The bug is in lib/redis.js line 291, where a strict inequality comparison (!==) between a string from prevData and a non-string new value incorrectly triggers index removal. Start by examining the updateAttributes flow, focusing on how prevData is populated via hgetall and how index updates are handled. Verify the fix by modifying the comparison to handle type coercion, then test with a model that has a numeric indexed field to ensure the index persists after an update.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, redis
- Bereich
- databases
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 65/100