GORM自引用树和性能
|
我正在为留言板实现自参考GORM对象。到目前为止,伪GORM类:
class Article {
String title
Article parent
static belongsTo = [parent: Article]
static hasMany = [children: Article]
static constraints = {
parent(nullable: true)
}
static transients = [\'descendants\', \'ancestors\']
def getDescendants() {
return children ? children*.descendants.flatten() + children : []
}
def getAncestors() {
return parent ? parent.ancestors.flatten() + this : []
}
}
因此,这在我的本地机器上可以正常工作,但我会担心它会在现场扩展成千上万的每日唯一身份。
自Burt Beckwith的演示文稿http://www.infoq.com/presentations/GORM-Performance以来,我倾向于不使用hasMany / belongsTo。
主要是阅读邮件而不是添加新邮件。
我可以缓存getDescendants和getAncestors调用。
我可以添加一个名为\“ hasChildren \”的新布尔值。可以使用覆盖addToChildren和removeFromChildren方法来操纵此字段。使用“ hasChildren \”可以防止类似
if (article.children.size() > 0) // show replies
代替:
if (article.hasChildren) // show replies
有什么想法吗?有什么建议吗?
提前致谢,
托德
没有找到相关结果
已邀请:
1 个回复
栖很钾是狠