/** reBuilds the fastDS data. This is called if the cached value is lost, or after upgrade. * * @param integer the maximum space allowed for caching this data. * * @return integer estimate of the space used. Note that we can't be exact. **/ protected function buildTemplates($maxSize) { self::$building = true; $styleid = vB::getDatastore()->getOption('styleid'); // Still don't have a language, fall back to master language if (!$styleid) { $styleid = -1; } $this->styleid = $styleid; //We sort by languageid, descending. So for a given template, the first // record we get is what we want. $templates = vB::getDbAssertor()->assertQuery('template', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'styleid' => array($styleid, 0, -1)), array('field' => array('styleid'), 'direction' => array(vB_dB_Query::SORT_DESC))); $size = 0; $this->templatesCached = true; $used = array(); foreach ($templates as $template) { if (isset($used[$template['title']])) { continue; } $used[$template['title']] = 1; if ($size + strlen($template['template']) > $maxSize) { //We weren't able to cache. Let's un-set whatever we have. foreach ($used as $template => $value) { $this->clearValue('tm' . $template); } $this->templatesCached = false; self::$building = false; return false; } $size += strlen($template['template']) + strlen($template['title']); $this->setTemplate($template['title'], $template['template']); } $this->tmRebuilt = vB::getRequest()->getTimeNow(); self::$building = false; return $size; }