1
votes

I'm using breeze to load some data from a remote SQL Server database in a MVC 4 application. The database has around 40 entities. The loading of metadata with breeze takes a lot of time: somewhere between 14s and 35 s even though the size is not that big: ~ 600 kb.

After the metadata is loaded the entities are fetched much faster. For example an entity of 2.5 Mb was loaded in 2.5s.

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

My question is:

Is there a reason why this loading is that slow and what would be a way to reduce the time of loading?

2
From the screenshot it seams that the problem is on the server. If this is what takes so long, then you can implement some caching mechanism on the server. Check how long it takes for the second client to fetch the metadata.pawel
I tried to fetch the data with a second client but the time was the same. I was thinking maybe there is a way to store the metadata in a file in the application so I could avoid the call to the server.Razvan
You can store it in a static field as a string.pawel
Thank you for the response! Apparently it is not loading the metadata but the connection to the SQL server that is slow. Any suggestions for that? dropbox.com/s/ajypwpgoyn8z24q/Capture.PNGRazvan
After some more research I found out that the Entity Framework is the one responsible with the delay. The bad part is that there doesn't seem to be a solution...Razvan

2 Answers

2
votes

I rarely ask the server for metadata once I get going. I quickly export the metadata from an EntityManager's metadata store and dump that into a JavaScript file as a global variable. I include it with my other scripts on my index.html. I load this var into my manager's metadateStore on launch.

I get progressively more sophisticated over time, regenerating it automatically when the server starts, serializing and storing it in browser local storage, etc. Once you realize that metadata is just a JS object, you hold the key to endless. Cleverness.

1
votes

You can eliminate the need for loading metadata in a separate network call from server by embedding it in your scripts and providing Breeze with it manually as @Ward suggested.

Here is how (I'm using TypeScript below):

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);

Now you have an EntityManager instance initialized with the metadata and ready to execute queries.

For more informtion, see official docs