具有30 000行的垫桌的性能

问题描述 投票:2回答:1

我使用Angular 6,Firebase和Angular Material。

我在firebase中存储了30,000个json对象,我想将它们加载到mat-table中。只有我低于我希望的方式。我等了30秒才能点击我的应用程序,有时铬错误...

然而,我在分页后加载了我的数据。

有人能告诉我这是否正常或是否有策略来克服这个问题?谢谢。

也许我可以用角度7和无限滚动来做到这一点?你有一个例子吗?

export class TableComponent implements OnInit {

    showSpinner = true;

    Data = {nom: '', finessgeo: '', cat1: '', commune: '', CP: '', departement: '', tel: ''}

    displayedColumns = ['nom', 'finessgeo', 'cat1', 'commune', 'CP', 'departement', 'tel'];

    dataSource = new MatTableDataSource();

    applyFilter(filterValue: string) {
        filterValue = filterValue.trim();
        filterValue = filterValue.toLowerCase();
        this.dataSource.filter = filterValue;
    }

    @ViewChild(MatPaginator) paginator: MatPaginator;

    @ViewChild(MatSort) sort: MatSort;

    ngAfterViewInit() {
        this.dataSource.paginator = this.paginator;
        this.dataSource.sort = this.sort;
        return this.geoService.getGeos().subscribe(res => {
            this.dataSource.data =
                res;
            this.showSpinner = false;
        });
    }

    constructor(public authService: AuthService, private geoService:
        GeoService, private router: Router, private database: AngularFireDatabase) {
    }

    ngOnInit() {}
}
angular performance firebase angular-material mat-table
1个回答
3
投票

我有一些建议。

第一:不要将所有30k行加载到客户端。尝试使用服务器端分页。这应该解决所有问题。此外,您必须在api上实现所有过滤和排序功能。使用客户端只显示该数据。

如果这不是一个选项:

  • 对服务器上的数据进行排序。尽快地。如果可以,直接在数据库内查询。
  • 检查组件是否将所有行添加到DOM中。这将需要非常多的CPU时间。
  • 使用chrome dev工具中的性能选项卡来检查花费的时间。并尝试优化它。
  • 检查你的html模板。尽量使行尽可能简单。像较少的嵌套元素,其他类等。
© www.soinside.com 2019 - 2024. All rights reserved.