cognoma / core-service

Cognoma Core API
Other
9 stars 12 forks source link

Index user.random_slugs #32

Open awm33 opened 8 years ago

awm33 commented 8 years ago

The user.random_slugs field is searched every time a request authenticates a user. Because that operation is run so often, this field should be indexed. The field is a postgres array type, an array of strings. It looks like the best way to index this is using gin.

This currently uses the __contains operation built into django. Will operation take advantage of an index? If not, we need to somehow use one that will, even if it means passing raw SQL. Most querysets (all?) expose a query property that can be used to see what sql was run, passing this to EXPLAIN in postgres will tell you if the index is being used.

dcgoss commented 7 years ago

I would like to clear up some confusion I have about the random_slugs field. I completely understand its use in "authenticating" a user, however I am confused about why it is an array. Why are there multiple random_slugs? And even if there are, could you just store the "authentication" slug in its own field and then index that directly?

bdolly commented 7 years ago

@awm made that filed an array in case a user accidentally created 2 accounts they could easily be merged into the array