应用程序引擎记录到数据库和实体组
在我的应用程序中,我有一个 Profile 实体,它有一些子实体,例如 ProfileAccount、ProfileLink 等。它们通常在事务中更新,就像
def update_profile(key):
profile = db.get(key)
accounts = db.query("SELECT * FROM ProfileAccount WHERE ANCESTOR IS :1", profile)
# do something with accounts and profile
profile.put()
我用 db.run_in_transaction(update_profile, key) 调用它一样,但我需要有一个更新配置文件时发生的所有事情的管理日志,因此我创建了一个通用的 AdminLog 实体,其中包含对配置文件的引用、时间戳和任意字符串数据。稍后将对此进行处理,以检查自上次用户登录以来发生的情况。
问题是,由于 AdminLog 不属于与配置文件相同的实体组,我无法将其添加到同一事务中,但另一方面,我认为将所有这些日志放在同一个事务下并不明智实体(个人资料),因为它不是重要数据。
我想到的一件事是配置文件上的 StringList,每次登录时都会清除该字符串列表,这样我就可以获得配置文件中发生的所有内容。您认为这是一个很好的方法吗?或者对于这种情况还有其他解决方法吗?
预先感谢您的任何提示
In my application I have a Profile entity, which have some children, like ProfileAccount, ProfileLink, etc. They're usually updated in a transaction, like
def update_profile(key):
profile = db.get(key)
accounts = db.query("SELECT * FROM ProfileAccount WHERE ANCESTOR IS :1", profile)
# do something with accounts and profile
profile.put()
I call it with db.run_in_transaction(update_profile, key), but I need to have an administrative log of everything that happens when the profile is updated, so I created a generic AdminLog entity which contains a reference to a Profile, the timestamp and arbitrary string data. This would be processed later to check what happened since the last user login.
The problem is as AdminLog doesn't belong to the same entity group as the Profile, I cannot add it on the same transaction, but on the other side, I don't think it would be clever to put all those logs under the same entity (Profile), as it's not essential data.
One thing I thought about would be a StringList on the Profile, that would be cleared on each login, so this way I'd have everything that happened to the profile. Do you think that's a nice approach, or maybe there's some other workaround for this kind of situation ?
Thanks in advance for any tips
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用子实体似乎是最好的选择。它确保您可以以事务方式更新它们,并将更改与它们所应用的实体相关联。如果您愿意,您可以对旧的管理日志条目进行垃圾收集以节省空间。
Using child entities seems like the best option. It ensures you can update them transactionally, and associates the changes with the entity they apply to. If you wish, you can garbage collect old admin log entries to save space.