Google Datastore删除实体不会立即更新,可以在下一行使用`find()`方法访问。

huangapple go评论61阅读模式
英文:

Google datastore delete entity does not immediately update, can access in next line with find()

问题

我遇到一个问题,即当删除实体后,数据存储表不会立即更新,并且可以使用DB.find来访问。

以下是流程:

  1. DB.find(key) --> 对象
  2. DB.delete(object)
  3. DB.find(key) --> 对象(非空)

我期望DB.find(key)返回null,因为对象未被删除,但事实并非如此。然而,当所有逻辑完成并且响应已经返回后,我看到实体已经成功删除。

为什么实体仍然可以在同一个函数内找到?

此外,每个DB访问步骤都使用ObjectifyService事务包装,例如:

Boolean txnRes = ObjectifyService.ofy().transact(new Boolean() {
            @Override
            public Boolean run() {
               object = DB.find(key)
               return object != null
            }
        });
英文:

I am running into an issue where the datastore table does not immediately update when an entity is deleted, and can be accessed with DB.find.

Here is the flow:

1. DB.find(key) --> object
2. DB.delete(object)
3. DB.find(key) --> object (not null) 

I expect DB.find(key) to return null because the object was not deleted but that is not the case. However, after all logic completes and response has been returned I see that the entity has been successfully deleted.

Why is the entity still able to be found within the same function?

Also, each of the DB access steps are wrapped with ObjectifyService transaction, for example:

Boolean txnRes = ObjectifyService.ofy().transact(new Boolean() {
            @Override
            public Boolean run() {
               object = DB.find(key)
               return object != null
            }
        });

答案1

得分: 1

根据此帖子上@Dan Cornilescu的回答,您必须在实体的键上调用.delete(),而不是在实体本身上。即

DB.key.delete()

还请查看此文档

英文:

As per the answer by @Dan Cornilescu on this thread. you have to call .delete() on the entity's key, instead of entity itself. I.e

DB.key.delete()

Also check this document

huangapple
  • 本文由 发表于 2023年5月30日 12:52:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76361699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定