TIL - GIN Indexes
Been meaning to post about this for a while, but I recently learned about Generalized Inverted Indexes. According to the Postgres docs:
GIN indexes are “inverted indexes” which are appropriate for data values that contain multiple component values, such as arrays. An inverted index contains a separate entry for each component value, and can efficiently handle queries that test for the presence of specific component values.
I plan to write a longer post about my exploration into this, including the pros and cons of denormalization, but I’ll give a short overview of a problem I was trying to solve and how the GIN index came into play.
At Reflektive, I’ve been working on a user profile feature that gives each person a personalized newsfeed of the feedbacks they have sent or received.
Over time, the types of feedback we have in Reflektive has grown, and with each type of feedback, specific rules around who can see the feedback. For example, a user can give somebody private feedback, and only those two individuals should be allowed to see it. Or, Person A can write a private note about Person B, and not share it with Person B. While this is still stored as a Feedback in our database, and Person B is the recipient, Person B should not be allowed to see that Feedback.
In total, we have 9 different types of feedbacks, and unless the feedback is public, the feedback is private and shared with, at most, 3 people.
TIL - Ruby Array Multiplication
Today I learned that if you call a multiplication operator on a Ruby array, it duplicates each element of the array by the multiplier.
So for example:
>> [1,2,3] * 3
=> [1, 2, 3, 1, 2, 3, 1, 2, 3]
>> ['Jared Rader'] * 3
=> ["Jared Rader", "Jared Rader", "Jared Rader"]