2

Hello so I'm trying to combine data retrieved from 3 different locations in my firebase. The data is structured as follows:

dashboard.data.post 
     dashboard.data.post.image
     dashboard.data.post.audio
     dashboard.data.post.text

When any user posts they are able to make a post underneath one of those blocks. I would like to be able to search underneath that block for all of the users posts and retrieve that information, combine it all, ordered by the data it was post and display it to the user. So far My method i feel is rudimentary and would appreciate as much help an advice as possible, even if it means restructuring my data.

info.block = $firebaseArray of the id's which the users have of their post
info.text is $firebaseArray of the texts post
info.image is $firebaseArray of the image post
info.audio is $firebaseArray of the audio post

var storage = function(text, image, audio, value, listStore) {
                var postkey = value.postid;
                angular.forEach(info.text, function(curr, key) {
                    if (postkey === curr.$id) {
                        listStore.push(curr);
                        return true;
                    }
                });
                angular.forEach(info.image, function(curr, key) {
                    if (postkey === curr.$id) {
                        listStore.push(curr);
                        return true;
                    }
                });
                angular.forEach(info.audio, function(curr, key) {
                    if (postkey === curr.$id) {
                        listStore.push(curr);
                        return true;
                    }
                });
            };

info.blog.$loaded().then(function() {
            info.text.$loaded().then(function() {
                info.image.$loaded().then(function() {
                    info.audio.$loaded().then(function() {
                        angular.forEach(info.blog, function(value, key) {
                            storage(info.text,info.image,info.audio,value,this);
                        }, $scope.randomObj);

                    });
                });
            });
        });
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Xavier
  • 313
  • 2
  • 5
  • 18
  • 1
    Few comments: this sort of normalized data structure will lead to way too many operations to remain performant when the number of items goes up. Do read https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html and http://stackoverflow.com/questions/16638660/firebase-data-structure-and-url/16651115#16651115. Also be aware that `$loaded` *only* fires after the initial data has loaded, while the object/array will be updated for all data changes too. Finally, have a look at https://github.com/firebase/firebase-util – Frank van Puffelen Jun 03 '15 at 03:51
  • Thank you I will look into those – Xavier Jun 03 '15 at 05:02

0 Answers0