dynarex-blog 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dynarex-blog.rb +21 -17
- metadata +1 -1
data/lib/dynarex-blog.rb
CHANGED
@@ -16,7 +16,8 @@ class DynarexBlog
|
|
16
16
|
@file_path = file_path[/\/$/] ? file_path : file_path + '/'
|
17
17
|
if File.exists? (@file_path + 'index.xml') then open(@file_path) else fresh_start() end
|
18
18
|
@current_lookup = '_entry_lookup.xml'
|
19
|
-
@
|
19
|
+
@hc_lookup = HashCache.new(size: 5)
|
20
|
+
@hc_result = HashCache.new(size: 5)
|
20
21
|
super()
|
21
22
|
end
|
22
23
|
|
@@ -143,27 +144,30 @@ class DynarexBlog
|
|
143
144
|
def select_page(lookup, number)
|
144
145
|
|
145
146
|
#doc = Document.new File.open(@file_path + lookup,'r').read
|
146
|
-
doc = @
|
147
|
-
|
148
|
-
|
147
|
+
doc = @hc_lookup.read(lookup) { Document.new File.open(@file_path + lookup,'r').read }
|
148
|
+
|
149
|
+
result = @hc_result.read(lookup + number.to_s) {
|
150
|
+
x1 = (number - 1) * 10
|
151
|
+
x2 = x1 + 9
|
149
152
|
|
150
|
-
|
153
|
+
a = XPath.match(doc.root,'records/entry').reverse[x1..x2]
|
151
154
|
|
152
|
-
|
155
|
+
xpath_ids = "entry[%s]" % a.map{|x| x.text('id').to_s}.map{|x| "@id='%s'" % x}.join(' or ')
|
153
156
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
157
|
+
temp_doc = Document.new '<root/>'
|
158
|
+
a.map{|x| x.text('file').to_s}.uniq.each do |file|
|
159
|
+
doc_entryx = Document.new File.open(@file_path + file,'r').read
|
160
|
+
XPath.each(doc_entryx.root,'records/entry') do |entry|
|
161
|
+
temp_doc.root.add entry
|
162
|
+
end
|
159
163
|
end
|
160
|
-
end
|
161
164
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
165
|
+
result = Document.new '<result><summary/><records/></result>'
|
166
|
+
records = XPath.first(result.root, 'records')
|
167
|
+
XPath.each(temp_doc.root, xpath_ids) do |record|
|
168
|
+
records.add record
|
169
|
+
end
|
170
|
+
}
|
167
171
|
|
168
172
|
result
|
169
173
|
end
|