Fastest way to do a search

Let’s say that I have a type of thing called “Message” and I want to show it to each one of my users but only do it once. Which one of these ways would be the fastest way to do it?

  1. Add a list field to the Message called Users Viewed and just use a standard search where Users Viewed doesn’t contain current users. For comparison purposes, let’s say each Message has 10,000 people who viewed it.

  2. Add a list field to User called Messages Viewed and use a filter on top of the search that eliminates all of the Messages that are on that user’s Messages Viewed list. Let’s say each user would have 300 messages they’ve viewed.

I know #1 is much faster usually because of Elastic Search but what if there is such a drastic difference in the number of items on the list?

2 Likes

Yeah, I would pick #2… The general rule is you want to shape your data such that each individual item isn’t too huge… .if one item has a 10,000 long list on it its going to be cumbersome performance-wise.

Another consideration is – I’m guessing your use case here is something like site-wide announcements? – presumably sufficiently old messages aren’t necessary any more, which means that if things start getting slow, you can limit the search for messages to those newer than X days.

2 Likes