title: Does Firebase know when data is no longer a part of query?
body: <p>In my Firebase database, I have children containing Unix times, and I'm querying by times that occur after the current time. I'm putting the data of each child which matches that criteria into a <code>UICollectionView</code>. When the current time surpasses the time of one of the children, I want for the child to expire, and to get removed from the <code>UICollectionView</code>. Currently, it isn't getting removed until I restart the app. Here is some of the code:</p>
  
  <pre><code>// in viewDidLoad
  self.events_query = Database.database().reference().child("events").queryOrdered(byChild: "end-time").queryStarting(atValue: Date().timeIntervalSince1970)
  
  // in viewWillAppear
  func observeAllEvents() {
      self.events_query.observe(.value, with: { (snapshot) in
  
          guard let eids_dict = snapshot.value as? [String : AnyObject] else { return }
          let eids = Array(eids_dict.keys)
  
          for eid in eids {
              print(eid)
          }
  
          Event.getAllEvents(with: eids, ref: self.events_query.ref, completion: { (events) in
  
              if let feed_datasource = self.datasource as? EventFeedDatasource {
                  feed_datasource.events = events
              }
  
              DispatchQueue.main.async {
                  self.collectionView?.reloadData()
              }
          })
  
      })
  }
  
  // in viewDidDisappear
  self.events_query.removeAllObservers()
  </code></pre>
  
  <p>Here's the function <code>getAllEvents</code>:</p>
  
  <pre><code>static func getAllEvents(with eids: [String], ref: DatabaseReference, completion: @escaping (_ events: [Event]) -&gt; Void) {
      var events = [Event]()
      let dispatch_groups = [DispatchGroup(), DispatchGroup()]
  
      for eid in eids {
          dispatch_groups[0].enter()
          ref.child(eid).observeSingleEvent(of: .value, with: { (snapshot) in
              guard let dictionary = snapshot.value as? [String : AnyObject] else { return }
              dispatch_groups[1].enter()
  
              // I'm not including `load` because all it does is parse the snapshot
              Event.load(with: dictionary, completion: { (event) in
                  events.append(event)
                  dispatch_groups[1].leave()
              })
              dispatch_groups[0].leave()
          })
      }
  
      dispatch_groups[0].notify(queue: DispatchQueue.main) {
          dispatch_groups[1].notify(queue: DispatchQueue.main) {
              completion(events)
          }
      }
  }
  </code></pre>