Skip to content

Heavy load methods

Anton Demushkin edited this page Apr 27, 2021 · 1 revision

Some methods of this library require level or parentId field. If you don't have any of the fields, they will be generated on the fly which may result in high load and slow work. A simple way to optimize this issue is to add one of columns or both:

  • level - int, not null. For its name you can also use levelColumnName option.
  • parentId - same as id column type, nullable. You can use another column name using parentIdColumnName option. Don't forget to set correct parentIdColumnType if your id is not an integer.

Here are the methods, conditions and possible optimizations (they may conflict, please choose the most applicable for you):

  • Model.fetchTree()
  • record.getDescendants()
  • record.getAncestors()
    • when: depth > 0 and you don't use level field
    • optimization: use level field
  • record.getParent()
    • when: depth > 0 and you don't use level field
    • optimization: use parentId or level field
  • record.insertAsParentOf()
    • when you use either level or parentId
    • optimization: don't use parentId and level fields

Clone this wiki locally