dramatic speed improvements
[booh] / bin / booh-backend
index e9fdf3f98802c1a8e3a7d9fca17e5a85bf5b9843..a524dcf3a3ca3794148f466ec93682d972c707cb 100755 (executable)
@@ -928,10 +928,15 @@ def walk_source_dir
                 counter = 0
                 pagecount = 0
                 reset_iterations(iterations)
+                #- preprocess the @filename->elem, rexml is very slow with that; we dramatically improve this part of the processing
+                optfilename = {}
+                xmldir.elements.each('image') { |elem|
+                    optfilename[elem.attributes['filename']] = elem
+                }
                 for file in entries
                     type = images.include?(file) ? 'image' : videos.include?(file) ? 'video' : nil
                     if type
-                        if type == 'image' && elem = xmldir.elements["image[@filename='#{utf8(file)}']"]
+                        if type == 'image' && elem = optfilename[utf8(file)]
                             if pano = pano_amount(elem)
                                 html_elem = run_iterations(iterations, pano)
                                 counter += count = pano.ceil
@@ -974,7 +979,7 @@ def walk_source_dir
                                                       img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
                             html_thumbnails_nojs.gsub!(/~~image_iteration~~/, 
                                                        '<a href="' + fullscreen_images[sizeobj['name']][index] + '" name="' + fullscreen_images[sizeobj['name']][index] + '">' +
-                                                           img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
+                                                       img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
                             #- remember in which thumbnails page is this element, for image->thumbnail link
                             if sizeobj == $images_size[0]
                                 image2thumbnailpage4js << pagecount
@@ -1228,16 +1233,19 @@ def walk_source_dir
         ios.close
 
         #- substitute multiple "return to albums", previous/next correctly
+        #- the following two statements are dramatical optimizations to executing for each substInFile callback
+        dirpresent = xmldir.elements['dir']
+        parentname = xmldir.parent.name
         if xmldir.child_byname_notattr('image', 'deleted') || xmldir.child_byname_notattr('video', 'deleted')
             for suffix in [ '', '-nojs' ]
                 for sizeobj in $images_size
                     Dir.glob("#{dest_dir}/thumbnails-#{size2js(sizeobj['name'])}#{suffix}-*.html") do |file|
                         substInFile(file) { |line|
                             sub_previous_next_album(previous_album, next_album, line)
-                            if xmldir.elements['dir']
+                            if dirpresent
                                 line.sub!(/~~return_to_albums~~/, '<a href="index.html">' + utf8(_('return to albums')) + '</a>')
                             else
-                                if xmldir.parent.name == 'dir'
+                                if parentname == 'dir'
                                     line.sub!(/~~return_to_albums~~/, '<a href="../index.html">' + utf8(_('return to albums')) + '</a>')
                                 else
                                     line.sub!(/~~return_to_albums~~/, '')