A
A
Alexander Ivanov2015-12-04 18:28:35
PHP
Alexander Ivanov, 2015-12-04 18:28:35

How to implement page loading ordering on MODX revo (eg via AXAJ)?

Suppose I have a website ready and it loads quickly, but I was given a task, the implementation of which will slow down its work.
For example, counting the number of resources in a directory:
b396932275224f4c9fbd30c4aaf5a572.jpg
This PHP SQL task will slow down the loading of the site, and it would be logical to load the count via AJAX after the loading itself, and replace the value with a gif until it loads.
How can this task be done more efficiently with MODX?
Snippet code that counts child elements:

$id=$modx->getOption('id',$scriptProperties,0);
if ($id == 0) return 'Не задан id страницы';
$depth = 10; //глубина вложенности
$arr = $modx->getChildIds($id,$depth);//получили массив ids всех потомков(и контейнеров и документов)
if (count($arr) == 0) return '0';
$c = $modx->newQuery('modResource');
$c->where(array(
  'id:IN'=>$arr, //выбираем только детей
  'isfolder'=>0  //отсекаем контейнеры
));
$c->limit = 0;
$docs=$modx->getCollection('modResource',$c);//получили коллекцию детей-документов
return count($docs);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2015-12-10
@cimonlebedev

docs.modx.pro/components/ajaxsnippet
docs.modx.pro/components/pdotools/snippets/pdomenu
&countChildren=`1`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question