breezejs:使用FetchStrategy.FromLocalCache时的inlineCount [英] breezejs: inlineCount when using FetchStrategy.FromLocalCache

查看:89
本文介绍了breezejs:使用FetchStrategy.FromLocalCache时的inlineCount的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当数据来自缓存而不是服务器时,将inlineCount添加到结果集中是否有意义?

Would it make sense to add inlineCount to the resultset when the data comes from the cache instead of the server ?

我将计数存储在本地,因此只要不保留当前网址(我使用angularjs),就可以从控制器中的变量中获取计数。但是,一旦我离开了该网址,如果返回该网址,数据仍将来自缓存,但是我的本地变量将重置为初始值。

I store the count locally, so as long as don't leave the current url (I use angularjs), I can get it from a variable in my controller. But once I've left that url, if I go back to it, the data will still come from the cache, but my local variable is reset to initial value.

推荐答案

2015年3月12日更新


必要的更改已提交,应该发布下一个版本(在1.5.3之后)。

Update 12 March 2015

The requisite changes have been committed and should make the next release (after 1.5.3).

当然, inlineCount 仅在异步查询执行中可用

Of course the inlineCount is only available in async query execution.


同步 em.executeQueryLocally(query)立即返回分页结果数组;没有任何地方可以容纳 inlineCount

The synchronous em.executeQueryLocally(query) returns immediately with the paged result array; there's no place to hold the inlineCount.

以下是新的对应测试的摘录DocCode.queryTests:" 可以用内联计数在缓存中查询页面的客户

Here's an excerpt from the new, corresponding test in DocCode.queryTests: "can page queried customers in cache with inline count"

  var query = EntityQuery.from('Customers')
      .where('CompanyName', 'startsWith', 'A')
      .orderBy('CompanyName')
      .skip(2).take(2)
      .inlineCount()
      .using(breeze.FetchStrategy.FromLocalCache);

  return em.executeQuery(query)
           .then(localQuerySucceeded);

  function localQuerySucceeded(data) {
    var custs = data.results;
    var count = custs.length;
    equal(count, 2,
        "have full page of cached 'A' customers now; count = " + count);

    var inlineCount = data.inlineCount;
    ok(inlineCount && inlineCount > 2,
      'have inlineCount=' + inlineCount + ' which is greater than page size');
  }


更新2014年5月9日


经过更多思考,我已经决定你们都正确,而我错了。我已经在我们的内部跟踪系统中输入了功能请求#2267。无法保证何时完成(我相信很快);

Update 9 May 2014

After more reflection, I've decided that you all are right and I have been wrong. I have entered feature request #2267 in our internal tracking system. No promise as to when we'll get it done (soon I trust); stay on us.

我认为支持 inlineCount ,因为Breeze无法计算该值。

I don't think it makes sense to support inlineCount for cache queries because Breeze can't calculate that value.

请与我一起逐步解决。您向服务器发出一个分页查询,其内联计数和页面大小为5。

Walk this through with me. You issue a paged query to the server with the inline count and a page size of 5 items.


// Get the first 5 Products beginning with 'C'
// and also get the total of all products beginning with 'C'
var query = EntityQuery.from("Products")
    .where("ProductName", "startsWith", "C")
    .take(5)
    .inlineCount()
    .using(manager);

假设您运行一次,并且服务器报告数据库中有142个 C客户。

Suppose you run this once and the server reports that there are 142 'C' customers in the database.

现在,请执行相同的查询并在本地执行:

Ok now take that same query and execute it locally:

query.using(FetchStrategy.FromLocalCache).execute().then(...).fail(...);

微风应该如何知道计数?缓存中只有5个实体。如何知道数据库中有142个 C客户?

How is Breeze supposed to know the count? It only has 5 entities in cache. How can it know that there are 142 'C' customers in the database? It can't.

我认为您最好的方法是检查返回的数据对象是否具有 inlineCount 值。仅在查询偏远时才重置计数的绑定副本。

I think you're best option is to check the returned data object to see if it has an inlineCount value. Only reset your bound copy of the count if the query went remote.

这篇关于breezejs:使用FetchStrategy.FromLocalCache时的inlineCount的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆