如何处理“参考数据” (静态数据)在 Google App Engine 数据存储区中?

发布于 2024-12-10 09:49:23 字数 375 浏览 2 评论 0原文

我正在开发一个应用程序,其中有一组数据,虽然技术上不是静态的,但不会经常更改(例如,平均每年 3 或 4 次)。然而,其中一些数据是相互关联的。

此类数据的一个示例是州和县 - 理想情况下,我们希望在输入地址或位置时了解所有可用的州,但我们还想知道每个州可用的县,因此我们可以向用户适当地显示该信息(即,当用户选择了某个州时,过滤掉不适当的县)。

过去,我在关系数据库中通过州和县表来完成此操作,其中县链接回其所属的州,州和县链接到需要其信息的任何表。

然而,这些数据并不被拥有,在 Google 数据存储中,即使我们没有主动修改这些数据,锁定事务机制似乎也会导致锁定发生。处理此类数据的最佳方法是什么?是否有一个没有父级(None/null 的父级)的实体?这会导致将来出现锁定问题吗?

I have an application I am working on where I have a set of data that, while not technically static, will not change very often (say, 3 or 4 times a year on average). However, some of this data is interrelated.

An example of this type of data would be states and counties - ideally, we would like to know all of the states available when putting in an address or location, but we would also like to know the counties available for each state, so we can display that information appropriately to the user (i.e. filtering out the inappropriate counties when a user has a state selected).

In the past, I have done this in a relational database by having a state and county table, where the county is linked back to the state it belongs in, and the state and counties are linked to any tables that need their information.

This data is not owned however, and in the Google datastore it seems like the locking transaction mechanism will cause locks to occur even though we are not actively modifying this data. What is the best way to handle this type of data? Is it to have an entity for the pieces that does not have a parent (parent of None/null)? Will this cause locking problems in the future?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲性难收 2024-12-17 09:49:23

我会考虑将其存储在代码内的优化数据结构中并手动更新。性能提升将是巨大的,并且由于谷歌会为此向您收费,因此您最终会为此表示感谢。

这个想法是将这种固定的数据结构与您的数据库混合在一起,这样您就可以为每个国家(或其他国家)提供一个 ID,并在模型中引用它。

一个简单的方法是列出一个国家/地区列表,每个国家/地区都有一个州列表。您可以在运行应用程序之前在 def main(): 中加载它们。当然,如果你不小心,这会带来各种各样的问题,但如果你小心的话,应该没问题。

更高级的方法是仅将最常用的、动态延迟加载和转储的国家/地区保留在内存中。

I'd consider storing this in an optimized data structure inside your code and updating it manually. The performance gain will be huge, and since google charges you for that, you will end up thanking for it.

The idea is to mix this fixed data structures with your database, so you give each country (or whatever) an id, and you reference it in your models.

A simple approach is making a list of countries and each have a list of states in them. You can load them in def main():, before you run the app. Of course this will bring all sorts of problems if you are not careful, but if you are, you should be fine.

A more advanced one would be to keep in memory only the most used, and lazy load and dump countries on the fly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文