Java 使用网格更改Vaadin 8延迟加载中的默认限制

Java 使用网格更改Vaadin 8延迟加载中的默认限制,java,aws-lambda,vaadin,lazy-loading,vaadin8,Java,Aws Lambda,Vaadin,Lazy Loading,Vaadin8,我已经用网格实现在vaadin8中实现了延迟加载 我的后端在AWS Lambda上运行,其响应对象的限制为6 MB 延迟加载实现为服务器提供了默认限制(40),这使得我的程序崩溃,错误为“body太大” 我想更改Vaadin中延迟加载的默认限制 下面是我的代码片段: grid.setDataProvider((sortorder, offset, limit) -> { try { return billingClient.getI

我已经用网格实现在vaadin8中实现了延迟加载

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

延迟加载实现为服务器提供了默认限制(40),这使得我的程序崩溃,错误为“body太大”

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

下面是我的代码片段:

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行大于6MB


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

通过手动更改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;
        }

    });

偏移量是根据我设定的限制进行调整的。

出于好奇(我认为,40件东西不应该破坏东西):你的付费客户也会拿到比你需要的更多的东西吗?e、 g.它是否也获取发票涉及的所有文件,还是忽略了限制?这可能只是普通的ORM胡说八道,试图用限制来解决这一问题可能会损害其他事情(例如,只针对大屏幕用户的更多查询,应用程序和数据库之间的巨大流量)。billingClient的响应对象是一个嵌套的对象列表,其中包含许多项目和与项目相关的税费。所以它本身就是一个巨大的物体,一切都是需要的。那么这才是你真正的问题。如果只需要在几列中显示一些文本,请不要请求整个对象图。@cfrick谢谢。我将实施这一点。此外,通过手动设置限制可以解决限制问题。是否在
数据提供程序中显示
通知
s?我不建议这样做,因为数据提供者(顾名思义)只是用来检索数据的。另外:将fetch方法中的限制更改为20如何解决您的问题?如果你没有像瓦丁期望的那样归还那么多物品,我希望瓦丁会表现得很糟糕。啊。。。我明白你的意思,硬编码限制。可能我还没有遇到过这种情况,所以工作正常。关于显示通知,这样显示通知有什么问题。我建议在DataProvider之外显示通知,例如当您将其设置为网格时。