使用微风加载元数据很慢

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

我正在使用breeze从MVC 4应用程序中的远程SQL Server数据库加载一些数据。该数据库有大约40个实体。使用微风加载元数据需要花费大量时间:大约在14秒到35秒之间,即使尺寸不是那么大:~600 kb。

加载元数据后,将更快地获取实体。例如,2.5 Mb的实体在2.5秒内加载。

https://www.dropbox.com/s/n8eqv5ezqr1qqlp/loading.png

我的问题是:

有没有理由说这种加载速度慢,哪种方法可以减少加载时间?

javascript asp.net .net entity-framework breeze
2个回答
2
投票

一旦我开始,我很少向服务器询问元数据。我从EntityManager的元数据存储中快速导出元数据,并将其作为全局变量转储到JavaScript文件中。我在index.html上将其与其他脚本一起包含在内。我在启动时将此var加载到我的经理的metadateStore中。

随着时间的推移,我逐渐变得越来越复杂,在服务器启动时自动重新生成它,将其序列化并将其存储在浏览器本地存储中等等。一旦你意识到元数据只是一个JS对象,你就可以掌握无穷无尽的关键。聪明。


1
投票

您可以通过将其嵌入到脚本中,并在@Ward建议的情况下手动提供Breeze,从而无需在服务器的单独网络调用中加载元数据。

这是如何(我在下面使用TypeScript):

import { DataService, EntityManager, MetadataStore, NamingConvention } from "breeze-client";

        // Your metadata object
        const metadata: any = Metadata.value;

        // define the Breeze `DataService` for this app
        const dataService: DataService = new DataService({
            serviceName: "http://localhost:63000",
            hasServerMetadata: false  // don't ask the server for metadata
        });

        // create the metadataStore 
        const metadataStore: MetadataStore = new MetadataStore({
            namingConvention: NamingConvention.camelCase // if you use this convention
        });

        // initialize it from the application's metadata variable
        metadataStore.importMetadata(metadata);

        const entityManagerConfig: EntityManagerOptions = {
            dataService: dataService,
            metadataStore: metadataStore
        };

        this.entityManager = new EntityManager(entityManagerConfig);

现在,您已经使用元数据初始化了EntityManager实例,并准备执行查询。

有关更多信息,请参阅qazxsw poi

© www.soinside.com 2019 - 2024. All rights reserved.