I'm implementing a self-reference GORM object for a message board. So far, pseudo GORM class:
class Article {
String title
Article parent
static belongsTo = [parent: Article]
static hasMany = [children: Article]
static constraints = {
parent(nullable: true)
}
static tran开发者_如何学编程sients = ['descendants', 'ancestors']
def getDescendants() {
return children ? children*.descendants.flatten() + children : []
}
def getAncestors() {
return parent ? parent.ancestors.flatten() + this : []
}
}
So, this works fine on my local box, but will it scale on site with thousands of daily uniques is my concern.
Ever since Burt Beckwith's presentation http://www.infoq.com/presentations/GORM-Performance and I'm inclined to not use hasMany / belongsTo.
It's going to be primarily read of the messages vs adding new.
I could cache the getDescendants and getAncestors calls.
I could add a new boolean called "hasChildren". This field could be manipulated with override addToChildren and removeFromChildren methods. The use of "hasChildren" could prevent things like
if (article.children.size() > 0) // show replies
instead:
if (article.hasChildren) // show replies
Thoughts? Suggestions?
Thanks in advance, Todd
I would just try it with SQL logging on. BTW why don't you use mappedBy?
精彩评论