如何删除不再使用的 OData 绑定? [英] How to Remove No Longer Used OData Bindings?

查看:30
本文介绍了如何删除不再使用的 OData 绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一个页面显示了一个复杂的数据结构(例如,一篇有很多细节的文章).该视图将不时通过重新绑定到不同的文章来重用.

Assume a page that shows a complex data structure (for example, an article with many details). This view will be reused from time to time by rebinding it to different articles.

现在,我注意到 ODataModel 将所有使用过的文章实体保存在内存中(如果它们不再绑定到任何控件).

Now, I noticed that the ODataModel keeps all used article entities in memory (also if they are no longer bound to any control).

这会导致两个问题:

  1. 内存消耗会随着时间的推移而增加(如果应用程序不会重新加载).
  2. 如果应用程序强制刷新数据模型,则所有实体都将被加载(也不使用).

第二个问题似乎是更大的问题.它会减慢应用程序的速度.

The second issue seems to be the bigger problem. It slows down the speed of the application.

我还没有找到解决该问题的方法.如果我使用 refresh(true, true) 似乎所有数据都将被重新加载.

I have not found a solution for that problem. If I use refresh(true, true) it seems all data will be reloaded.

有没有办法清理模型?

假设您有一个包含数千篇文章的列表.用户可以单击其中一篇文章并导航到该文章的详细屏幕.客户端的 OData 模型将缓存它.要查看它,请执行以下操作:

Lets say you have a list of thousands of articles. User can click on one of the articles and will navigate to a detailed screen of that article. The OData model in client side will cache this. To see it, do something like:

var oModel = this.getModel("modelName");

使用调试器查看 oModel.oData.

如果用户现在返回并选择下一篇文章,这也将被缓存.

If the user now navigates back and chooses the next article, this will be cached as well.

如果用户执行此操作 1000 次,则所有文章现在都在模型中.如果您触发 oModel.refresh(true);,所有这些数据(1000 篇文章)将被重新加载,而不仅仅是绑定到视图的数据.

If user does this 1000 times, all articles are now in the model. If you trigger a oModel.refresh(true);, all these data (of 1000 articles) will be reloaded not only the one bound to the view.

现在我的应用程序不是关于显示文章信息.这是一个带有子项的更复杂的结构.每次用户访问此页面时,都会缓存更多数据(并在模型上进行 refresh 调用时重新获取).

Now my application is not about showing article information. It's a more complex structure with subitems. Each time user is visiting this page, more data will be cached (and re-fetched in case of a refresh call on the model).

函数 updateBindings(bForceUpdate?) 似乎有点帮助.不管怎样,ODataModel 类中还是有数据积累的.这意味着:自下一次重新加载(F5)整个页面以来,每个访问过的数据路径都将保留在内存中.如果有人在一天内使用这样的应用程序,数据累积并且模型上的刷新调用将再次读取所有数据,如果仍然<强>绑定到视图或不.

The function updateBindings(bForceUpdate?) seems to help a little bit. Anyhow, the data accumulation is still there in the ODataModel class. That means: Each visited data path will stay in memory since the next reload (F5) of the full page. If someone uses such an application over a day, the data accumulates and a refresh call on the model will read all data again, if still bound to a view or not.

推荐答案

尝试 deleteCreatedEntry(oContext).即使这不是此方法的假设用例,它也可以在不触发后端请求的情况下从模型中删除实体.

Try deleteCreatedEntry(oContext). Even though this is not the supposed use case for this method it might work to delete an entity from the model without triggering a backend request.

如果 updateBindings(bForceUpdate?) 仅触发实际绑定实体的更新.

You could also try if updateBindings(bForceUpdate?) only triggers an update on actually bound entities.

这篇关于如何删除不再使用的 OData 绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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