locked
LS HTML Inefficient data fetching? RRS feed

  • Question

  • Something I’ve just noticed with a LS HTML 2013 app working on, and I’m wondering if there is a way to fix it?

    For a data model:

    • Order has a Product
    • Product has a Manufacturer

    On my browse screen UI I have a table of Orders which includes a summary field bound to Orders(item).Product.Manufacturer.

    This displays fine, but what I have noticed is that the Manufacturer data appears to be being fetched multiple times:

    • TestData.svc/Orders?$expand=Product/Manufacturer,Product&$top=45 (which includes all the manufacturer details in the response)
    • TestData.svc/Manufacturers?$filter=Id%20eq%201 (repeated for each manufacturer shown in the Orders table)

    The first request looks like how it should be done, getting all the data in one hit to the data service, but then there are multiple per-item hits to the data service which seem redundant (as they are for data already fetched in the first call), and like they would slow things down a lot over a high-latency connection.

    Is there some way to fix this in my code?

    Thanks

    Thursday, May 8, 2014 12:42 AM

Answers

  • Hi Simon,

    That is very interesting. The 'Orders' query requests the 'Manufacturer' to be expanded but then does not use it ( or does it?).

    LightSwitch will take the 'Manufacturer' from cache if it exists so the extra requests should diminish (depending on data population). My test here has 5 unique manufacturers and after approximately 10 requests it gets everything from cache. Overlapping requests occur here because of cache misses.

    To me, it looks like it should not request the 'Manufacturer' data per se without explicitly wanting it. When I set to exclude 'Manufacturer' data, it still request it and I think that it should not (?).

    When I change the 'Manufacturer' data to explicitly 'Included' then it works as expected with no separate requests, so that should fix your situation so that all data is streamed in one request.

    The most efficient method depends on the volume and population of 'Manufacturers' and 'Orders/Products'. But it seems 'Excluded' does not work in my tests; this seems like a bug.

    I tested using VS2013 with March'2014 Update.

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    • Proposed as answer by Xpert360 Thursday, May 8, 2014 4:59 PM
    • Marked as answer by Simon Hardman Thursday, May 8, 2014 9:19 PM
    Thursday, May 8, 2014 4:57 PM

All replies

  • Hi Simon,

    That is very interesting. The 'Orders' query requests the 'Manufacturer' to be expanded but then does not use it ( or does it?).

    LightSwitch will take the 'Manufacturer' from cache if it exists so the extra requests should diminish (depending on data population). My test here has 5 unique manufacturers and after approximately 10 requests it gets everything from cache. Overlapping requests occur here because of cache misses.

    To me, it looks like it should not request the 'Manufacturer' data per se without explicitly wanting it. When I set to exclude 'Manufacturer' data, it still request it and I think that it should not (?).

    When I change the 'Manufacturer' data to explicitly 'Included' then it works as expected with no separate requests, so that should fix your situation so that all data is streamed in one request.

    The most efficient method depends on the volume and population of 'Manufacturers' and 'Orders/Products'. But it seems 'Excluded' does not work in my tests; this seems like a bug.

    I tested using VS2013 with March'2014 Update.

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    • Proposed as answer by Xpert360 Thursday, May 8, 2014 4:59 PM
    • Marked as answer by Simon Hardman Thursday, May 8, 2014 9:19 PM
    Thursday, May 8, 2014 4:57 PM
  • Another option that I often use for Tables is to create a database view that returns exactly the right columns that you need.

    Regards, Xander. My Blog

    Thursday, May 8, 2014 8:29 PM
  • That's the answer.  The relevant item in my query (Manufacturer) was set to "Included (Auto)".  LS was generating the Orders query correctly with the Manufacturer data included, but then ignoring it and making separate calls to get the Manufacturer data.  I tried changing the Manufacturer item to explicitly "Included" in the query, and the extra calls to Manufacturer disappear and everything works as I would expect.

    So it looks like there is a bug where implicitly included data in the query is ignored if it is a grandchild or deeper of the main query (seems to work for direct children).  Do you happen to know where to log bugs for LightSwitch?

    Thanks

    Thursday, May 8, 2014 9:19 PM
  • Hi Simon,

    Microsoft Connect

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Thursday, May 8, 2014 10:54 PM