我正在使用breeze从MVC 4应用程序中的远程SQL Server数据库加载一些数据。该数据库有大约40个实体。使用微风加载元数据需要花费大量时间:大约在14秒到35秒之间,即使尺寸不是那么大:~600 kb。
加载元数据后,可以更快地获取实体。例如,2.5 Mb的实体在2.5秒内加载。
https://www.dropbox.com/s/n8eqv5ezqr1qqlp/loading.png
我的问题是:
有没有理由说这种加载速度慢,哪种方法可以减少加载时间?
答案 0 :(得分:2)
一旦我开始,我很少向服务器询问元数据。我从EntityManager的元数据存储中快速导出元数据,并将其作为全局变量转储到JavaScript文件中。我在index.html上将其与其他脚本一起包含在内。我在启动时将此var加载到我的经理的metadateStore中。
随着时间的推移,我逐渐变得越来越复杂,在服务器启动时自动重新生成它,将其序列化并存储在浏览器本地存储中等等。一旦你意识到元数据只是一个JS对象,你就可以把握钥匙。聪明。
答案 1 :(得分: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
实例,并准备执行查询。
如需更多信息,请参阅official docs