English 中文(简体)
绘制谷歌应用发动机的可测量产品数据库
原标题:Designing a scalable product database on Google App Engine

我建立了三部分产品数据库。 每个部分都有包含标签的“子”部分。 但是,我越是同它合作,它感到更加不稳定。 此外,我每次增加一次,都需要更多的法典才能工作。

产品是零部件,每一部分都是一类产品。 每个产品、部件和类型都有标签。 每个语言都有一个标签。

产品包含2个清单中的部分。 缺省部分(每类一个)和选修部分清单。

现在我想增加货币组合,并作出决定,重新调整我处理此事的整个方式。

我想要得到的结果是一份清单,列出所有产品目标,其中包括与部件对应的名称、描述、价格、所有部件和所有类型。 对于这些正确的语言标签。

与此类似:

product
    - name
    - description (by language)
    - price (by currency)
    - parts
        - part (type name and part name by language)
        - partPrice (by currency)

我目前的设置是一个荒谬的混合体。 参考资料和db.ListProperty(db.key)

获取所有数据是需要多功能通路、配对字塔和数据储存电话的斜线。 其实,它只是一片东西。

重读(未经测试)就是这样。

class Products(db.model)
    name = db.StringProperty()
    imageUrl = db.StringProperty()
    optionalParts = db.ListProperty(db.Key)
    defaultParts = db.ListProperty(db.Key)
    active = db.BooleanProperty(default=True)

    @property
    def itemId(self):
        return self.key().id()

class ProductPartTypes(db.Model):
    name= db.StringProperty()

    @property
    def itemId(self):
        return self.key().id()

class ProductParts(db.Model):    
    name = db.StringProperty()
    type = db.ReferenceProperty(ProductPartTypes)
    imageUrl = db.StringProperty()
    parts = db.ListProperty(db.Key)

    @property
    def itemId(self):
        return self.key().id()


class Labels(db.Model)
    key = db.StringProperty() #want to store a key here
    language = db.StringProperty()
    label = db.StringProperty()

class Price(db.Model)
    key = db.StringProperty() #want to store a key here
    language = db.StringProperty()
    price = db.IntegerProperty()

这里的主要事情是,我把拉比斯和价格分开。 因此,这些产品可以包含任何产品、部件或种类的标签和价格。

因此,我很奇怪的是,从建筑角度看,这是否是一个牢固的解决办法? 即使每个模式有数千个条目,这还是会维持吗?

此外,欢迎以良好方式检索数据的任何假设。 我目前的解决办法是,首先获取所有数据,然后通过浏览,把数据贴在字典上,但感觉到这样的情况可能失败。

.fredrik

问题回答

你们需要牢记,评估引擎的数据储存要求你重新考虑设计数据库的通常方式。 这首先违反了直观,但如果你希望你的申请能够加以衡量,你必须尽量使你的数据脱节。 数据库就是这样设计的。

我通常采取的做法是首先考虑在不同的使用案件中需要做何种询问,例如,我需要同时检索哪些数据? 秩序如何? 应当对哪些特性进行指数化?

如果我理解正确的话,你的主要目标就是列出一份附有完整细节的产品清单。 BTW, 如果您有其他询问情景——即: 过滤价格、类型等——也应当考虑到这一点。

为了收集你所需要的全部数据,我建议你建立一种模式,可以这样看:

class ProductPart(db.Model):
    product_name = db.StringProperty()
    product_image_url = db.StringProperty()
    product_active = db.BooleanProperty(default=True)
    product_description = db.StringListProperty(indexed=False) # Contains product description in all languages
    part_name = db.StringProperty()
    part_image_url = db.StringProperty()
    part_type = db.StringListProperty(indexed=False) # Contains part type in all languages
    part_label = db.StringListProperty(indexed=False) # Contains part label in all languages
    part_price = db.ListProperty(float, indexed=False) # Contains part price in all currencies
    part_default = db.BooleanProperty()
    part_optional = db.BooleanProperty()

关于这一解决办法:

  • ListProperties are set to indexed=False in order to avoid exploding indexes if you don t need to filter on them.
  • In order to get the right description, label or type, you will have to set list values always in the same order. For example : part_label[0] is English, part_label[1] is Spanish, etc. Same idea for prices and currencies.
  • After fetching entities from this model you will have to do some in-memory manipulations in order to get the data nicely structured the way you want, maybe in a new dictionary.

显然,这种设计在数据库中将有很多多余之处,但这种oka,因为它使你能够以可衡量的方式质疑数据储存。

此外,这并不是要取代你所铭记的架构,而是为你需要做的那种用户查询专门设计的另一种模式。 检索完整的产品/部分信息清单。

这些产品 部分实体可以按背景任务分类,复制位于作为权威数据来源的其他正常实体的数据。 由于你在应用引擎上储存了大量数据,这不应成为问题。

海事组织你的设计大多是有意义的。 在阅读你的问题陈述之后,我确实提出了几乎相同的设计。 有几个不同之处

  • I had prices with Product and ProductPart not as a separate table.
  • Other difference was part_types. If there are not many part_type you can simply have them as python list/tuple.

part_types = (wheel ,break , app. /code>

这还取决于你预计会提出的询问。 如果对自然价格计算存在许多疑问(取决于产品的其他部分和部分信息),那么,设计这种价格的方法或许是明智的。

你提到,你将首先获得所有数据。 是否可能存在 t问? 如果你把全部数据输入你的手表,然后将数据带入正.,那将是缓慢的。 你们正在考虑哪一个数据库? 对我来说,我们喜欢一个好的选择。

最后,为什么你怀疑大约1 000个记录? 你可以事先对你的 d子进行几次测试。

最佳做法





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...