Firestore strategy for excluding items the user has already seen

Viewed 71

Imagine a tinder-like app.

  • Users see a feed of items, and rate some of them
  • The feed is loaded in batches of 20 items
  • Each batch should include the latest items, but exclude the ones the user has rated

So, I first load the collection of the user's rated items, and then:

const itemsCollection = await firebase.firestore().collection('items')
        .orderBy('id')
        .where('id', 'not-in', userRatedItems)
        .orderBy('publish_date', 'desc')
        .limit(20)
        .get();

The problem is that 'not-in' is limited to searching in a list of 10 items, and the user's past ratings could be in the thousands.

I could theoretically load all rated items, and remove them from the list of candidates, but:

  1. I don't know how many items to query for, since I don't know how many will be excluded as already rated
  2. I have a feeling that there is a better strategy for what I am trying to do
0 Answers
Related