title: Is it ok to load all users from Cloud Functions for Firebase and loop through them?
body: <p>My app is very much like Tinder.
  And I'm trying to do, that every time new users come join the app, old users will get notified by push notification, to come back, and swipe thru the new users, so there will eventually be a match.</p>
  
  <p>I'm using Firebase Realtime Database, and thinking about implementing it in this way:</p>
  
  <p>From server (Cloud Functions for Firebase) load all users.
  Loop through them, and check there searching priorities (Age and Distance) and users that already have swiped, And filter out the rest of the users. If filtered users (Users that match priorities and have not yet seen) are more than 10, send push notification to user.</p>
  
  <p>Now this has a few problems:</p>
  
  <ol>
  <li>Loading all users, I'm not sure this is best practice, but not sure what are the downside of it since this is done on the server.</li>
  <li>It's slow looping thru all users, but It's done on the server.</li>
  </ol>
  
  <p>My question, is this bad practice? If so what are the downsides? And what better options do I have?</p>
  
  <p>Thanks!
  And sorry about the long explanation with no code example, but I think it's better this way.</p>