【问题标题】:Changing default limit in Vaadin 8 lazy loading with grid使用网格更改 Vaadin 8 延迟加载中的默认限制
【发布时间】:2018-02-20 14:36:00
【问题描述】:

我在 Vaadin 8 中通过网格实现实现了延迟加载。

我的后端在 AWS Lambda 上运行,响应对象的限制为 6 MB。

延迟加载实现为服务器提供了默认限制(40),这使我的程序崩溃并给出“body too large”错误。

我想更改 Vaadin 中延迟加载的默认限制。

下面是我的代码sn-p:

grid.setDataProvider((sortorder, offset, limit) -> {

            try {
                return billingClient.getInvoiceListByCriteria(criteria, (long) offset, (long) limit).stream();
            } catch (Exception e) {
                logger.error("Exception while getInvoiceListByCriteria", e);
                return null;
            }
        }, () -> {

            try {
                totalInvoices = billingClient.getCountInvoiceListByCriteria(criteria).longValue();
                Integer count = totalInvoices.intValue();
                if (count == 0)
                    Notification.show("No Invoices found.", Notification.Type.HUMANIZED_MESSAGE);
                return count;
            } catch (Exception e) {
                logger.error("Error occured while getting count calling getCountInvoiceListByCriteria", e);
                Notification.show("Error while getting count", Notification.Type.ERROR_MESSAGE);
                return null;
            }

        });

【问题讨论】:

  • 出于好奇(我认为,这 40 件东西不应该破坏东西):您的 billingClient 是否也获得了超出您需要的数量?例如它是否还获取了与发票有关的所有文件,还是忽略了限制?这可能只是通常的 ORM 废话,尝试通过限制来解决这个问题可能只会损害其他东西(例如,更多查询只针对大屏幕的人,您的应用程序和数据库之间的巨大流量)。
  • billingClient 的响应对象是一个嵌套的对象列表,其中包含许多项目和与项目相关的税收。所以它本身就是一个巨大的物体,一切都是必需的。
  • 那么这是你真正的问题。如果您只需要在几列中显示一些文本,请不要请求整个对象图。
  • @cfrick 谢谢。我会实施的。也可以通过手动设置限制来解决限制问题。

标签: java aws-lambda vaadin lazy-loading vaadin8


【解决方案1】:

奇怪的是 40 行大于 6MB。

从未尝试过,但您可以使用 grid.getDataCommunicator().setMinPushSize(size) 设置最小项目数。它用 40 初始化,所以我想你可以降低它以防止你的响应变大。但是名称中的“min”表示其他因素也可能对其产生影响,因此您需要对其进行彻底测试。

【讨论】:

    【解决方案2】:

    通过手动更改limit的值解决了这个问题。

    grid.setDataProvider((sortorder, offset, limit) -> {
    
            try {
                limit=20;
                return billingClient.getInvoiceListByCriteria(criteria, (long) offset, (long) limit).stream();
            } catch (Exception e) {
                logger.error("Exception while getInvoiceListByCriteria", e);
                return null;
            }
        }, () -> {
    
            try {
                totalInvoices = billingClient.getCountInvoiceListByCriteria(criteria).longValue();
                Integer count = totalInvoices.intValue();
                if (count == 0)
                    Notification.show("No Invoices found.", Notification.Type.HUMANIZED_MESSAGE);
                return count;
            } catch (Exception e) {
                logger.error("Error occured while getting count calling getCountInvoiceListByCriteria", e);
                Notification.show("Error while getting count", Notification.Type.ERROR_MESSAGE);
                return null;
            }
    
        });
    

    根据我设置的限制调整偏移量。

    【讨论】:

    • 您是否在DataProvider 中显示Notifications?我不建议这样做,因为数据提供者——顾名思义——只是为了检索数据。另外:在 fetch 方法中将限制更改为 20 如何解决您的问题?当您没有返回 Vaadin 预期的那么多项目时,我希望 Vaadin 会表现出错误。
    • 啊...我明白了你对限制进行硬编码的观点。可能是我没有遇到这种情况,所以它工作正常。关于显示通知,显示这样的通知有什么问题。有什么替代方案。
    • 我建议在 DataProvider 之外显示通知,例如当您将其设置为网格时。
    猜你喜欢
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 2023-04-02
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    相关资源
    最近更新 更多