存储检索数据:Firebase中的图像非常慢

时间:2013-08-04 15:46:18

标签: firebase

我刚尝试在Firebase中存储data:image

测试的图像文件大小小于500kb,只有1张图像。

存储和检索图像没问题但是当用text更新其他值时变得非常慢。

每个字母更改差不多延迟2分钟。

有什么想法吗?

**我可以直接使用http://www.google.com/image.png

更新

我创建一个描述的plunker请检查出来 http://plnkr.co/edit/lRy5vCbu0RXR2pEPKC7y?p=preview

1 个答案:

答案 0 :(得分:4)

每次更改字母时,您都在检索数据库中的每个图像。这是因为您已将angularFire实例同步到整个图像层次结构。由于angularFire使用on('value'),因此它会在每次更改时下载整个图像列表。

你可以通过使用angularFireCollection来避免这种情况,它依赖于child_added / updated / removed,这样它就可以在每个孩子改变时同步每个孩子而不是所有图像。

更好的解决方案是将图像数据拆分为单独的路径,并在images /中放置某种更新计数器,以便您可以随时更改新图像。这些甚至需要实时同步吗?图像是否经常“编辑”?

var app = angular.module('plunker', ['firebase']);

app.controller('MainCtrl', function($scope, angularFire) {
  $scope.name = 'World';

  $scope.images = angularFireCollection('https://datauri.firebaseio-demo.com/images/');

});

查看this article on denormalization了解某些背景信息。