Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 56 additions & 6 deletions Util/Factory/Query/DoctrineBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,16 @@ public function getData(array $filter_fields=[])
{
$query->setMaxResults($iDisplayLength)->setFirstResult($request->get('iDisplayStart'));
}
$objects = $query->getResult(Query::HYDRATE_OBJECT);

// we can conserve memory by iterating, also see below
if (true === $this->getConserveMemory())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming to shouldConserveMemory

{
$iterable_result = $query->iterate($query->getParameters(), Query::HYDRATE_OBJECT);
}
else
{
$objects = $query->getResult(Query::HYDRATE_OBJECT);
}
$data = array();
$entity_alias = $this->entity_alias;
$joins = $this->joins;
Expand Down Expand Up @@ -497,18 +506,59 @@ public function getData(array $filter_fields=[])
$property->setAccessible(true);
return $property->getValue($object);
};
foreach ($objects as $object)

// we can conserve memory by both detaching the entities and not returning them
if (true === $this->getConserveMemory())
{
$item = array();
foreach ($this->fields as $_field)
$objects = []; // leave empty on purpose
while ((list($obj) = $iterable_result->next()) !== false)
{
$item[] = $__getValue($__getKey($_field), $object, $has_add_select, $_field);
$item = array();
foreach ($this->fields as $_field)
{
$item[] = $__getValue($__getKey($_field), $obj, $has_add_select, $_field);
}
$data[] = $item;

$this->em->detach($has_add_select ? $obj[0] : $obj);
}
$data[] = $item;
}
else
{
foreach ($objects as $object)
{
$item = array();
foreach ($this->fields as $_field)
{
$item[] = $__getValue($__getKey($_field), $object, $has_add_select, $_field);
}
$data[] = $item;
}
}

return array($data, $objects);
}

/**
* Experimental feature to conserve memory usage. Will use an iterator and
* detach the entities from the EntityManager. Also does not give the
* entities back to the renderer. Might lead to problems for some datatables.
*
* @param boolean $conserve_memory
*/
public function setConserveMemory($conserve_memory)
{
$this->conserve_memory = $conserve_memory;
}

/**
* @return bool
*/
public function getConserveMemory()
{
return $this->conserve_memory;
}

/**
* get entity name
*
Expand Down
2 changes: 1 addition & 1 deletion Util/Formatter/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function applyTo(array &$data, array $objects)
$view = 'AliDatatableBundle:Renderers:_default.html.twig';
}
$params = array_merge($params, array(
'dt_obj' => $objects[$row_index],
'dt_obj' => isset($objects[$row_index]) ? $objects[$row_index] : null,
'dt_item' => $data[$row_index][$column_index],
'dt_id' => $identifier_raw
)
Expand Down