使用 Spring Data 对 Google Cloud 数据存储条目进行批量部分更新的有效方法

发布于 2025-01-18 09:41:25 字数 727 浏览 4 评论 0原文

我在Google DataStore中有一种有数以万计的条目。我正在使用弹簧数据连接并在数据存储器上工作。我正在尝试在数据存储上更新一个(数百个)行的一个实体。

我试图使用的方法具有分页率,并更新所需的属性,并使用datastoreRepo.saveall(列表)保存所有条目,然后重复直到可用于查询条件的行。 Something like :

void partialUpdateSomething () { 
    List<Trains> trains = repo.findBySourceAndIsRunning("cityCode", false, Pageable.ofSize(50)); 
    while (!trains.isEmpty()) { 
        for(Train t:trains) { 
            train.isRunning(true); // updating isRunning to true 
        } 
        repo.saveAll(trains); // saving all the updated train objects 
        trains = repo.findBySourceAndIsRunning("cityCode", false, Pageable.ofSize(50)); 
    } 
}

Is there a better way to update just one or more entities ?

I have a kind in google datastore with tens thousands of entries. I am using spring data to connect to and work on the datastore. I am trying to update one entity on a few (hundreds) rows on datastore.

The method I am trying to use does multiple gets with pagination and update the required attribute and saves all entries using dataStoreRepo.saveAll(list) and repeat until there are rows available for the query criteria.
Something like :

void partialUpdateSomething () { 
    List<Trains> trains = repo.findBySourceAndIsRunning("cityCode", false, Pageable.ofSize(50)); 
    while (!trains.isEmpty()) { 
        for(Train t:trains) { 
            train.isRunning(true); // updating isRunning to true 
        } 
        repo.saveAll(trains); // saving all the updated train objects 
        trains = repo.findBySourceAndIsRunning("cityCode", false, Pageable.ofSize(50)); 
    } 
}

Is there a better way to update just one or more entities ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文