From 9876e37309f0c9c4d1ca4d067e02a6533258e1a7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Aug 2020 15:47:02 +0200 Subject: [PATCH] A little perf and memory enhancement when building category tree --- htdocs/categories/class/categorie.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index d5a2f76ecd5..7d3cdfde518 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1213,7 +1213,8 @@ class Categorie extends CommonObject //print 'Result for id_categ='.$id_categ.' : '.$this->cats[$id_categ]['fullpath'].'
'."\n"; // We count number of _ to have level - $this->cats[$id_categ]['level'] = dol_strlen(preg_replace('/[^_]/i', '', $this->cats[$id_categ]['fullpath'])); + $nbunderscore = substr_count($this->cats[$id_categ]['fullpath'], '_'); + $this->cats[$id_categ]['level'] = ($nbunderscore ? $nbunderscore : null); return; }