Merge lp:~sebastian-meyer/goobi-presentation/performance-optimization into lp:~sebastian-meyer/goobi-presentation/old-trunk

Proposed by Sebastian Meyer
Status: Merged
Approved by: Sebastian Meyer
Approved revision: 11
Merged at revision: 10
Proposed branch: lp:~sebastian-meyer/goobi-presentation/performance-optimization
Merge into: lp:~sebastian-meyer/goobi-presentation/old-trunk
Diff against target: 290 lines (+52/-99)
4 files modified
dlf/common/class.tx_dlf_document.php (+19/-85)
dlf/common/class.tx_dlf_indexing.php (+1/-1)
dlf/plugins/metadata/class.tx_dlf_metadata.php (+1/-1)
dlf/plugins/toc/class.tx_dlf_toc.php (+31/-12)
To merge this branch: bzr merge lp:~sebastian-meyer/goobi-presentation/performance-optimization
Reviewer Review Type Date Requested Status
Sebastian Meyer Approve
Review via email: mp+62962@code.launchpad.net

Commit message

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

To post a comment you must log in.
Revision history for this message
Sebastian Meyer (sebastian-meyer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dlf/common/class.tx_dlf_document.php'
2--- dlf/common/class.tx_dlf_document.php 2011-04-01 15:53:16 +0000
3+++ dlf/common/class.tx_dlf_document.php 2011-05-31 10:41:13 +0000
4@@ -208,23 +208,6 @@
5 protected static $registry = array ();
6
7 /**
8- * This holds the smLinks of the document
9- *
10- * @var array
11- * @access protected
12- */
13- protected $smLinks = array ();
14-
15- /**
16- * Are the METS file's smLinks loaded?
17- * @see $smLinks
18- *
19- * @var boolean
20- * @access protected
21- */
22- protected $smLinksLoaded = FALSE;
23-
24- /**
25 * This holds the PID for the structure definitions
26 *
27 * @var integer
28@@ -320,7 +303,7 @@
29 *
30 * @param mixed $uid: The unique identifier of the document to parse or URL of XML file
31 * @param integer $pid: If > 0, then only document with this PID gets loaded
32- * @param boolean $forceReload: Force reloading the document
33+ * @param boolean $forceReload: Force reloading the document instead of returning the cached instance
34 *
35 * @return tx_dlf_document Instance of this class
36 */
37@@ -396,8 +379,6 @@
38 // Load physical pages and smLinks.
39 $this->_getPhysicalPages();
40
41- $this->_getSmLinks();
42-
43 $_struct = $_div[0];
44
45 $this->registerNamespaces($_struct);
46@@ -415,44 +396,28 @@
47
48 $_details['type'] = (string) $_struct['TYPE'];
49
50- // Get the physical pages or external file this structure element is pointing at.
51- $_details['points'] = array ();
52+ // Get the physical page or external file this structure element is pointing at.
53+ $_details['points'] = '';
54
55 // Is there a mptr node?
56 if (($_mptr = $_struct->xpath('./mets:mptr[@LOCTYPE="URL"]'))) {
57
58 // Yes. Get the file reference.
59- $_details['points'][] = (string) $_mptr[0]->attributes('http://www.w3.org/1999/xlink')->href;
60+ $_details['points'] = (string) $_mptr[0]->attributes('http://www.w3.org/1999/xlink')->href;
61
62 // Are there any physical pages?
63 } elseif ($this->physicalPages) {
64
65- // Yes. Get all physical pages related to this structure element.
66- if (!empty($this->smLinks[(string) $_struct['ID']])) {
67-
68- foreach ($this->smLinks[(string) $_struct['ID']] as $_smLink) {
69-
70- $_key = tx_dlf_helper::array_search_recursive($_smLink, $this->physicalPages);
71-
72- // Check if smLink points to the "physSequence" element.
73- if ($_key === 0) {
74-
75- $_keys = array_keys($this->physicalPages);
76-
77- array_shift($_keys);
78-
79- $_details['points'] = $_keys;
80-
81- } else {
82-
83- $_details['points'][] = $_key;
84-
85- }
86-
87- }
88+ // Yes. Get first physical page related to this structure element.
89+ if (($_smLink = $this->mets->xpath('./mets:structLink/mets:smLink[@xlink:from="'.(string) $_struct['ID'].'"]'))) {
90+
91+ $_details['points'] = tx_dlf_helper::array_search_recursive($_smLink[0]->attributes('http://www.w3.org/1999/xlink')->to, $this->physicalPages);
92+
93+ // Check if smLink points to the "physSequence" element (in which case it should point to the first image).
94+ $_details['points'] = max(intval($_details['points']), 1);
95
96 // Get page number of the first page related to this structure element.
97- $_details['pagination'] = $this->physicalPages[$_details['points'][0]]['label'];
98+ $_details['pagination'] = $this->physicalPages[$_details['points']]['label'];
99
100 } else {
101
102@@ -665,20 +630,20 @@
103 // Get all logical structure nodes with metadata.
104 if (($_divs = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID]'))) {
105
106- $this->_getSmLinks();
107-
108 foreach ($_divs as $_div) {
109
110+ $_id = (string) $_div['ID'];
111+
112 // Are there physical structure nodes for this logical structure?
113- if (!empty($this->smLinks[(string) $_div['ID']])) {
114+ if ($this->mets->xpath('./mets:structLink/mets:smLink[@xlink:from="'.$_id.'"]')) {
115
116 // Yes. That's what we're looking for.
117- return (string) $_div['ID'];
118+ return $_id;
119
120 } elseif (!$id) {
121
122 // No. Remember this anyway, but keep looking for a better one.
123- $id = (string) $_div['ID'];
124+ $id = $_id;
125
126 }
127
128@@ -1041,9 +1006,9 @@
129 // Get UID of superior document.
130 $partof = 0;
131
132- if (!empty($this->tableOfContents[0]['points'][0]) && !t3lib_div::testInt($this->tableOfContents[0]['points'][0])) {
133+ if (!empty($this->tableOfContents[0]['points']) && !t3lib_div::testInt($this->tableOfContents[0]['points'])) {
134
135- $superior = tx_dlf_document::getInstance($this->tableOfContents[0]['points'][0]);
136+ $superior = tx_dlf_document::getInstance($this->tableOfContents[0]['points']);
137
138 if ($superior->pid != $pid) {
139
140@@ -1417,37 +1382,6 @@
141 }
142
143 /**
144- * This builds an array of all smLinks of the document
145- *
146- * @access protected
147- *
148- * @return array The smLinks of the document
149- */
150- protected function _getSmLinks() {
151-
152- if (!$this->smLinksLoaded) {
153-
154- $_smLinks = $this->mets->xpath('./mets:structLink/mets:smLink');
155-
156- if ($_smLinks) {
157-
158- foreach ($_smLinks as $_smLink) {
159-
160- $this->smLinks[(string) $_smLink->attributes('http://www.w3.org/1999/xlink')->from][] = (string) $_smLink->attributes('http://www.w3.org/1999/xlink')->to;
161-
162- }
163-
164- }
165-
166- $this->smLinksLoaded = TRUE;
167-
168- }
169-
170- return $this->smLinks;
171-
172- }
173-
174- /**
175 * This returns $this->sPid via __get()
176 *
177 * @access protected
178
179=== modified file 'dlf/common/class.tx_dlf_indexing.php'
180--- dlf/common/class.tx_dlf_indexing.php 2011-04-01 15:53:16 +0000
181+++ dlf/common/class.tx_dlf_indexing.php 2011-05-31 10:41:13 +0000
182@@ -354,7 +354,7 @@
183
184 $solrDoc->setField('pid', $doc->pid);
185
186- $solrDoc->setField('page', $logicalUnit['points'][0]);
187+ $solrDoc->setField('page', $logicalUnit['points']);
188
189 $solrDoc->setField('partof', $doc->parentid);
190
191
192=== modified file 'dlf/plugins/metadata/class.tx_dlf_metadata.php'
193--- dlf/plugins/metadata/class.tx_dlf_metadata.php 2011-04-01 15:53:16 +0000
194+++ dlf/plugins/metadata/class.tx_dlf_metadata.php 2011-05-31 10:41:13 +0000
195@@ -226,7 +226,7 @@
196
197 }
198
199- $_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']);
200+ $_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']);
201
202 // Translate name of holding library.
203 } elseif ($_index_name == 'owner') {
204
205=== modified file 'dlf/plugins/toc/class.tx_dlf_toc.php'
206--- dlf/plugins/toc/class.tx_dlf_toc.php 2011-04-01 15:53:16 +0000
207+++ dlf/plugins/toc/class.tx_dlf_toc.php 2011-05-31 10:41:13 +0000
208@@ -40,6 +40,14 @@
209 public $scriptRelPath = 'plugins/toc/class.tx_dlf_toc.php';
210
211 /**
212+ * This holds the active entries according to the currently selected page
213+ *
214+ * @var array
215+ * @access protected
216+ */
217+ protected $activeEntries = array ();
218+
219+ /**
220 * This builds an array for one menu entry
221 *
222 * @access protected
223@@ -67,15 +75,15 @@
224 $entryArray['ITEM_STATE'] = 'NO';
225
226 // Build menu links based on the $entry['points'] array.
227- if (!empty($entry['points'][0]) && t3lib_div::testInt($entry['points'][0])) {
228-
229- $entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('page' => $entry['points'][0]), TRUE, FALSE, $this->conf['targetPid']);
230-
231- } elseif (!empty($entry['points'][0]) && is_string($entry['points'][0])) {
232-
233- $_doc = tx_dlf_document::getInstance($entry['points'][0], ($this->conf['excludeOther'] ? $this->conf['pages'] : 0));
234-
235- $entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('id' => ($_doc->pid ? $_doc->uid : $entry['points'][0]), 'page' => 1), TRUE, FALSE, $this->conf['targetPid']);
236+ if (!empty($entry['points']) && t3lib_div::testInt($entry['points'])) {
237+
238+ $entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('page' => $entry['points']), TRUE, FALSE, $this->conf['targetPid']);
239+
240+ } elseif (!empty($entry['points']) && is_string($entry['points'])) {
241+
242+ $_doc = tx_dlf_document::getInstance($entry['points'], ($this->conf['excludeOther'] ? $this->conf['pages'] : 0));
243+
244+ $entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('id' => ($_doc->pid ? $_doc->uid : $entry['points']), 'page' => 1), TRUE, FALSE, $this->conf['targetPid']);
245
246 } elseif (!empty($entry['points']['doc'])) {
247
248@@ -88,7 +96,7 @@
249 }
250
251 // Set "ITEM_STATE" to "CUR" if this entry points to current page.
252- if (!empty($this->piVars['page']) && in_array($this->piVars['page'], $entry['points'])) {
253+ if (in_array($entry['id'], $this->activeEntries)) {
254
255 $entryArray['ITEM_STATE'] = 'CUR';
256
257@@ -102,14 +110,14 @@
258 // 2. Current menu node is in rootline
259 // 3. Current menu node points to another file
260 // 4. There are no physical pages in the current METS file
261- if (!empty($this->conf['menuConf.']['expAll']) || $entryArray['ITEM_STATE'] == 'CUR' || is_string($entry['points'][0]) || !$this->doc->physicalPages) {
262+ if (!empty($this->conf['menuConf.']['expAll']) || $entryArray['ITEM_STATE'] == 'CUR' || is_string($entry['points']) || !$this->doc->physicalPages) {
263
264 $entryArray['_SUB_MENU'] = array ();
265
266 foreach ($entry['children'] as $_child) {
267
268 // Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page.
269- if (!empty($this->piVars['page']) && in_array($this->piVars['page'], $_child['points'])) {
270+ if (in_array($_child['id'], $this->activeEntries)) {
271
272 $entryArray['ITEM_STATE'] = 'ACT';
273
274@@ -216,6 +224,17 @@
275 // Does the document have physical pages or is it an external file?
276 if ($this->doc->physicalPages || !t3lib_div::testInt($this->doc->uid)) {
277
278+ // Get all logical units the current page is a part of.
279+ if (!empty($this->piVars['page']) && $this->doc->physicalPages) {
280+
281+ foreach ($this->doc->mets->xpath('./mets:structLink/mets:smLink[@xlink:to="'.$this->doc->physicalPages[$this->piVars['page']]['id'].'"]') as $_logId) {
282+
283+ $this->activeEntries[] = (string) $_logId->attributes('http://www.w3.org/1999/xlink')->from;
284+
285+ }
286+
287+ }
288+
289 // Go through table of contents and create all menu entries.
290 foreach ($this->doc->tableOfContents as $_entry) {
291

Subscribers

People subscribed via source and target branches

to all changes: