Fix Bug #733338: Loading of large documents is very slow.

This commit is contained in:
Sebastian Meyer 2011-05-31 14:30:08 +02:00
commit 2db1c907df
4 changed files with 46 additions and 93 deletions

View File

@ -207,23 +207,6 @@ class tx_dlf_document {
*/
protected static $registry = array ();
/**
* This holds the smLinks of the document
*
* @var array
* @access protected
*/
protected $smLinks = array ();
/**
* Are the METS file's smLinks loaded?
* @see $smLinks
*
* @var boolean
* @access protected
*/
protected $smLinksLoaded = FALSE;
/**
* This holds the PID for the structure definitions
*
@ -320,7 +303,7 @@ class tx_dlf_document {
*
* @param mixed $uid: The unique identifier of the document to parse or URL of XML file
* @param integer $pid: If > 0, then only document with this PID gets loaded
* @param boolean $forceReload: Force reloading the document
* @param boolean $forceReload: Force reloading the document instead of returning the cached instance
*
* @return tx_dlf_document Instance of this class
*/
@ -396,8 +379,6 @@ class tx_dlf_document {
// Load physical pages and smLinks.
$this->_getPhysicalPages();
$this->_getSmLinks();
$_struct = $_div[0];
$this->registerNamespaces($_struct);
@ -415,44 +396,28 @@ class tx_dlf_document {
$_details['type'] = (string) $_struct['TYPE'];
// Get the physical pages or external file this structure element is pointing at.
$_details['points'] = array ();
// Get the physical page or external file this structure element is pointing at.
$_details['points'] = '';
// Is there a mptr node?
if (($_mptr = $_struct->xpath('./mets:mptr[@LOCTYPE="URL"]'))) {
// Yes. Get the file reference.
$_details['points'][] = (string) $_mptr[0]->attributes('http://www.w3.org/1999/xlink')->href;
$_details['points'] = (string) $_mptr[0]->attributes('http://www.w3.org/1999/xlink')->href;
// Are there any physical pages?
} elseif ($this->physicalPages) {
// Yes. Get all physical pages related to this structure element.
if (!empty($this->smLinks[(string) $_struct['ID']])) {
// Yes. Get first physical page related to this structure element.
if (($_smLink = $this->mets->xpath('./mets:structLink/mets:smLink[@xlink:from="'.(string) $_struct['ID'].'"]'))) {
foreach ($this->smLinks[(string) $_struct['ID']] as $_smLink) {
$_details['points'] = tx_dlf_helper::array_search_recursive($_smLink[0]->attributes('http://www.w3.org/1999/xlink')->to, $this->physicalPages);
$_key = tx_dlf_helper::array_search_recursive($_smLink, $this->physicalPages);
// Check if smLink points to the "physSequence" element.
if ($_key === 0) {
$_keys = array_keys($this->physicalPages);
array_shift($_keys);
$_details['points'] = $_keys;
} else {
$_details['points'][] = $_key;
}
}
// Check if smLink points to the "physSequence" element (in which case it should point to the first image).
$_details['points'] = max(intval($_details['points']), 1);
// Get page number of the first page related to this structure element.
$_details['pagination'] = $this->physicalPages[$_details['points'][0]]['label'];
$_details['pagination'] = $this->physicalPages[$_details['points']]['label'];
} else {
@ -665,20 +630,20 @@ class tx_dlf_document {
// Get all logical structure nodes with metadata.
if (($_divs = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID]'))) {
$this->_getSmLinks();
foreach ($_divs as $_div) {
$_id = (string) $_div['ID'];
// Are there physical structure nodes for this logical structure?
if (!empty($this->smLinks[(string) $_div['ID']])) {
if ($this->mets->xpath('./mets:structLink/mets:smLink[@xlink:from="'.$_id.'"]')) {
// Yes. That's what we're looking for.
return (string) $_div['ID'];
return $_id;
} elseif (!$id) {
// No. Remember this anyway, but keep looking for a better one.
$id = (string) $_div['ID'];
$id = $_id;
}
@ -1041,9 +1006,9 @@ class tx_dlf_document {
// Get UID of superior document.
$partof = 0;
if (!empty($this->tableOfContents[0]['points'][0]) && !t3lib_div::testInt($this->tableOfContents[0]['points'][0])) {
if (!empty($this->tableOfContents[0]['points']) && !t3lib_div::testInt($this->tableOfContents[0]['points'])) {
$superior = tx_dlf_document::getInstance($this->tableOfContents[0]['points'][0]);
$superior = tx_dlf_document::getInstance($this->tableOfContents[0]['points']);
if ($superior->pid != $pid) {
@ -1416,37 +1381,6 @@ class tx_dlf_document {
}
/**
* This builds an array of all smLinks of the document
*
* @access protected
*
* @return array The smLinks of the document
*/
protected function _getSmLinks() {
if (!$this->smLinksLoaded) {
$_smLinks = $this->mets->xpath('./mets:structLink/mets:smLink');
if ($_smLinks) {
foreach ($_smLinks as $_smLink) {
$this->smLinks[(string) $_smLink->attributes('http://www.w3.org/1999/xlink')->from][] = (string) $_smLink->attributes('http://www.w3.org/1999/xlink')->to;
}
}
$this->smLinksLoaded = TRUE;
}
return $this->smLinks;
}
/**
* This returns $this->sPid via __get()
*

View File

@ -354,7 +354,7 @@ class tx_dlf_indexing {
$solrDoc->setField('pid', $doc->pid);
$solrDoc->setField('page', $logicalUnit['points'][0]);
$solrDoc->setField('page', $logicalUnit['points']);
$solrDoc->setField('partof', $doc->parentid);

View File

@ -226,7 +226,7 @@ class tx_dlf_metadata extends tx_dlf_plugin {
}
$_value = $this->pi_linkTP(htmlspecialchars($_value), array ($this->prefixId => array ('id' => $this->doc->uid, 'page' => (!empty($details['points']) ? intval($details['points'][0]) : 1))), TRUE, $this->conf['targetPid']);
$_value = $this->pi_linkTP(htmlspecialchars($_value), array ($this->prefixId => array ('id' => $this->doc->uid, 'page' => (!empty($details['points']) ? intval($details['points']) : 1))), TRUE, $this->conf['targetPid']);
// Translate name of holding library.
} elseif ($_index_name == 'owner') {

View File

@ -39,6 +39,14 @@ class tx_dlf_toc extends tx_dlf_plugin {
public $scriptRelPath = 'plugins/toc/class.tx_dlf_toc.php';
/**
* This holds the active entries according to the currently selected page
*
* @var array
* @access protected
*/
protected $activeEntries = array ();
/**
* This builds an array for one menu entry
*
@ -67,15 +75,15 @@ class tx_dlf_toc extends tx_dlf_plugin {
$entryArray['ITEM_STATE'] = 'NO';
// Build menu links based on the $entry['points'] array.
if (!empty($entry['points'][0]) && t3lib_div::testInt($entry['points'][0])) {
if (!empty($entry['points']) && t3lib_div::testInt($entry['points'])) {
$entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('page' => $entry['points'][0]), TRUE, FALSE, $this->conf['targetPid']);
$entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('page' => $entry['points']), TRUE, FALSE, $this->conf['targetPid']);
} elseif (!empty($entry['points'][0]) && is_string($entry['points'][0])) {
} elseif (!empty($entry['points']) && is_string($entry['points'])) {
$_doc = tx_dlf_document::getInstance($entry['points'][0], ($this->conf['excludeOther'] ? $this->conf['pages'] : 0));
$_doc = tx_dlf_document::getInstance($entry['points'], ($this->conf['excludeOther'] ? $this->conf['pages'] : 0));
$entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('id' => ($_doc->pid ? $_doc->uid : $entry['points'][0]), 'page' => 1), TRUE, FALSE, $this->conf['targetPid']);
$entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('id' => ($_doc->pid ? $_doc->uid : $entry['points']), 'page' => 1), TRUE, FALSE, $this->conf['targetPid']);
} elseif (!empty($entry['points']['doc'])) {
@ -88,7 +96,7 @@ class tx_dlf_toc extends tx_dlf_plugin {
}
// Set "ITEM_STATE" to "CUR" if this entry points to current page.
if (!empty($this->piVars['page']) && in_array($this->piVars['page'], $entry['points'])) {
if (in_array($entry['id'], $this->activeEntries)) {
$entryArray['ITEM_STATE'] = 'CUR';
@ -102,14 +110,14 @@ class tx_dlf_toc extends tx_dlf_plugin {
// 2. Current menu node is in rootline
// 3. Current menu node points to another file
// 4. There are no physical pages in the current METS file
if (!empty($this->conf['menuConf.']['expAll']) || $entryArray['ITEM_STATE'] == 'CUR' || is_string($entry['points'][0]) || !$this->doc->physicalPages) {
if (!empty($this->conf['menuConf.']['expAll']) || $entryArray['ITEM_STATE'] == 'CUR' || is_string($entry['points']) || !$this->doc->physicalPages) {
$entryArray['_SUB_MENU'] = array ();
foreach ($entry['children'] as $_child) {
// Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page.
if (!empty($this->piVars['page']) && in_array($this->piVars['page'], $_child['points'])) {
if (in_array($_child['id'], $this->activeEntries)) {
$entryArray['ITEM_STATE'] = 'ACT';
@ -216,6 +224,17 @@ class tx_dlf_toc extends tx_dlf_plugin {
// Does the document have physical pages or is it an external file?
if ($this->doc->physicalPages || !t3lib_div::testInt($this->doc->uid)) {
// Get all logical units the current page is a part of.
if (!empty($this->piVars['page']) && $this->doc->physicalPages) {
foreach ($this->doc->mets->xpath('./mets:structLink/mets:smLink[@xlink:to="'.$this->doc->physicalPages[$this->piVars['page']]['id'].'"]') as $_logId) {
$this->activeEntries[] = (string) $_logId->attributes('http://www.w3.org/1999/xlink')->from;
}
}
// Go through table of contents and create all menu entries.
foreach ($this->doc->tableOfContents as $_entry) {