2

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 transients = ['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

Todd M
  • 1,012
  • 1
  • 15
  • 25

1 Answers1

0

I would just try it with SQL logging on. BTW why don't you use mappedBy?

Community
  • 1
  • 1
Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91