title: Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly
body: <p>I have an array of keys which lead to post objects for my social network like so /posts/id/(post info) </p>
  
  <p>When I load the posts I load /posts/0 and then /posts/1 etc using the <code>observeSingleEventOfType(.Value)</code> method. </p>
  
  <p>I use a <code>lazyTableView</code> to load 30 at a time and it is quite slow. Is there any way I can use one of the query methods or another way of making it faster even if I have to restructure the data in my JSON tree. </p>
  
  <p>I am coming from Parse re-implementing my app and so far the experience as been quite good. Just this one thing I am a bit stuck on. Thanks in advance for the help!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>func loadNext(i: Int) { 
  
      // check if exhists
      let ideaPostsRef = Firebase(url: "https://APPURL")
  
      ideaPostsRef.childByAppendingPath(i.description).observeSingleEventOfType(.Value, withBlock: {
          (snapshot) in
  
          if i % 29 == 0 &amp;&amp; i != 0 &amp;&amp; !self.hitNull { return }
              // false if nil
              // true if not nil
          if !(snapshot.value is NSNull) {
              let postJSON  = snapshot.value as! [String: AnyObject]
              print("GOT VALID \(postJSON)")
              let post = IdeaPost(message: postJSON["message"] as! String, byUser: postJSON["user"] as! String, withId: i.description)
              post.upvotes = postJSON["upvotes"] as! Int
              self.ideaPostDataSource.append(post)
              self.loadNext(i + 1)
          } else {
              // doesn't exhist
              print("GOT NULL RETURNING AT \(i)")
              self.doneLoading = true
              self.hitNull = true
              return
          }
      }
  }
  </code></pre>
  
  <p>This recursive function essentially runs getting the value for key number i from firebase. If it is NSNULL it knows that is the last possible post to load and never does again. If NSNULL doesn't get hit but <code>i % 29 == 0</code> then it returns as a base case so only 30 posts are loaded at a time (0 indexed). When I set <code>doneLoading</code> to <code>true</code>, <code>tableView.reloadData()</code> is called using a property observer. </p>
  
  <p>Here is a sample of what the array I am fetching looks like </p>
  
  <pre><code>"ideaPosts" : [ {
      "id" : 0,
      "message" : "Test",
      "upvotes" : 1,
      "user" : "Anonymous"
    }, {
      "id" : 1,
      "message" : "Test2",
      "upvotes" : 1,
      "user" : "Anonymous"
    } ]
  </code></pre>