Backport asynchronous thumbnail generation from Kabuki.
This commit is contained in:
@@ -11,12 +11,14 @@ class AssetIterator extends Asset
|
||||
private $return_format;
|
||||
private $res_assets;
|
||||
private $res_meta;
|
||||
private $res_thumbs;
|
||||
|
||||
protected function __construct($res_assets, $res_meta, $return_format)
|
||||
protected function __construct($res_assets, $res_meta, $res_thumbs, $return_format)
|
||||
{
|
||||
$this->db = Registry::get('db');
|
||||
$this->res_assets = $res_assets;
|
||||
$this->res_meta = $res_meta;
|
||||
$this->res_thumbs = $res_thumbs;
|
||||
$this->return_format = $return_format;
|
||||
}
|
||||
|
||||
@@ -41,6 +43,19 @@ class AssetIterator extends Asset
|
||||
// Reset internal pointer for next asset.
|
||||
$this->db->data_seek($this->res_meta, 0);
|
||||
|
||||
// Looks up thumbnails.
|
||||
$row['thumbnails'] = [];
|
||||
while ($thumbs = $this->db->fetch_assoc($this->res_thumbs))
|
||||
{
|
||||
if ($thumbs['id_asset'] != $row['id_asset'])
|
||||
continue;
|
||||
|
||||
$row['thumbnails'][$thumbs['selector']] = $thumbs['filename'];
|
||||
}
|
||||
|
||||
// Reset internal pointer for next asset.
|
||||
$this->db->data_seek($this->res_thumbs, 0);
|
||||
|
||||
if ($this->return_format == 'object')
|
||||
return new Asset($row);
|
||||
else
|
||||
@@ -51,6 +66,7 @@ class AssetIterator extends Asset
|
||||
{
|
||||
$this->db->data_seek($this->res_assets, 0);
|
||||
$this->db->data_seek($this->res_meta, 0);
|
||||
$this->db->data_seek($this->res_thumbs, 0);
|
||||
}
|
||||
|
||||
public function clean()
|
||||
@@ -135,7 +151,29 @@ class AssetIterator extends Asset
|
||||
ORDER BY id_asset',
|
||||
$params);
|
||||
|
||||
$iterator = new self($res_assets, $res_meta, $return_format);
|
||||
// Get a resource object for the asset thumbs.
|
||||
$res_thumbs = $db->query('
|
||||
SELECT id_asset, filename,
|
||||
CONCAT(
|
||||
width,
|
||||
{string:x},
|
||||
height,
|
||||
IF(mode != {string:empty}, CONCAT({string:_}, mode), {string:empty})
|
||||
) AS selector
|
||||
FROM assets_thumbs
|
||||
WHERE id_asset IN(
|
||||
SELECT id_asset
|
||||
FROM assets AS a
|
||||
WHERE ' . $where . '
|
||||
)
|
||||
ORDER BY id_asset',
|
||||
$params + [
|
||||
'empty' => '',
|
||||
'x' => 'x',
|
||||
'_' => '_',
|
||||
]);
|
||||
|
||||
$iterator = new self($res_assets, $res_meta, $res_thumbs, $return_format);
|
||||
|
||||
// Returning total count, too?
|
||||
if ($return_count)
|
||||
|
||||
Reference in New Issue
Block a user