Вопрос

I'm using Firebase's PHP API to update a Reporting/Dashboard AngularJS app as users do things through our application. The problem is sometimes when I do things too fast Angular app doesn't receive the new data from Firebase immediately. Then all of a sudden it receives a ton of new objects all at once instead of getting them one at a time as they happen.

Is firebase throttling the number of requests to their API? Is this a architecture design flaw?

Laravel framework http://laravel.com/

As you can see nothing special happening here.

$fb = new firebase(Config::get('firebase.url'), Config::get('firebase.token'));
$fb->push("/" . Config::get('firebase.reports_feed') . "/" . Auth::user()->account_user_id, array(
    'createdAt' => Date::timezone(Date::sql(), "UTC", Auth::user()->account()->timezone),
    'message' => Auth::user()->name . " activated a '{$record->card->name}' system.",
    'user' => array(
        'id' => Auth::user()->id,
        'name' => Auth::user()->name,
    ),
    'reload' => false,
    'processed' => false,
    'record' => to_json($record),
));

The card object is shallow.

enter image description here

Update

I have two computers I'm testing this on.

  • A cheap touchscreen acer - Windows7
  • An older compaq - ElementaryOS

I noticed the compaq tends to update before the acer does. Maybe this is a RAM issue with javascript vars being to large? I currently have an array of 225 objects in an activity feed.

Update 2

  1. I did an action in my app
  2. it posted to firebase
  3. Forge went green as it added the records
  4. Nothing happened with my listener.
  5. I did the action one to three more times and my app would update all of a sudden.

controllers.controller('ReportsCtrl', function($scope, angularFire) { var ref = new Firebase($scope.main.firebaseUrl + "/" + $scope.main.accountUserId); $scope.feedItems = []; angularFire(ref, $scope, "feedItems");

$scope.$watch('feedItems', function(newVal, oldVal) {
    _.each($scope.feedItems, function(item) {
        if (!item.processed) {
            toastr.info(item.message); // alert message that pops up
            item.processed = true;

            if (item.reload)
                $scope.loadGoalStats();
        }
    });

    $scope.feedItemsLength = _.toArray($scope.feedItems).length;
}, true);

});

Это было полезно?

Решение

Just launched our application into production and for sure the bottleneck lies with PHP doing something it wasn't meant to do. I solved this by reorganizing code and keeping everything in angularjs to firebase as much as possible.

In my case I was making waaaay to many curl requests repeatedly. So offset that to client side instead of server side and it worked MUCH better. (for obvious reasons)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top