Optimize HasAdditionalImages tag

1 view
Skip to first unread message

Alexander Obuhovich

unread,
Mar 19, 2010, 12:16:56 PM3/19/10
to In-Portal Development
I propose to make category item tag HasAdditionalImages look like this:

/**
         * Allows to detect if item has any additional images available
         *
         * @param Array $params
         * @return string
         */
        function HasAdditionalImages($params)
        {
            static $cache = null;

            $object =& $this->getObject($params);
            /* @var $object kDBList */

            if (!isset($cache)) {
                $resource_ids = $object->GetCol('ResourceId');

                $sql = 'SELECT ImageId, ResourceId
                        FROM ' . $this->Application->getUnitOption('img', 'TableName') . '
                        WHERE ResourceId IN (' . implode(',', $resource_ids) . ') AND DefaultImg != 1 AND Enabled = 1
                        GROUP BY ResourceId';
                $cache = $this->Conn->GetCol($sql, 'ResourceId');
            }

            $resource_id = $object->GetDBField('ResourceId');

            return array_key_exists($resource_id, $cache) ? $cache[$resource_id] : false;
        }

This will allow to check for category item additional images during list printing without additional sql for each printed category item.


--
Best Regards,

http://www.in-portal.com
http://www.alex-time.com

Dmitry Andrejev

unread,
Mar 19, 2010, 12:40:20 PM3/19/10
to in-por...@googlegroups.com
Good idea!

Here is a task:

631: Optimize HasAdditionalImages tag using single SQL for Lists

To unsubscribe from this group, send email to in-portal-dev+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Phil ..:: domicilis.biz ::..

unread,
Mar 19, 2010, 12:41:47 PM3/19/10
to in-por...@googlegroups.com
I support all actions which will result in lower db requests :)

2010/3/19 Alexander Obuhovich <aik....@gmail.com>:

Reply all
Reply to author
Forward
0 new messages