| 2262 | doc.NODES = []; |
| 2263 | |
| 2264 | var reader = function(parent, id, depth) { |
| 2265 | |
| 2266 | if ((options.depth && depth >= options.depth) || (tmp[id])) { |
| 2267 | process(); |
| 2268 | return; |
| 2269 | } |
| 2270 | |
| 2271 | tmp[id] = 1; |
| 2272 | |
| 2273 | self.read(id, function(err, links, linkid) { |
| 2274 | |
| 2275 | if (linkid && !tmp[linkid]) { |
| 2276 | pending.push({ id: linkid, parent: parent, depth: depth }); |
| 2277 | sort = true; |
| 2278 | } |
| 2279 | |
| 2280 | // because of seeking on HDD |
| 2281 | links.quicksort('ID'); |
| 2282 | |
| 2283 | var fil; |
| 2284 | |
| 2285 | links.wait(function(item, next) { |
| 2286 | |
| 2287 | var key = item.ID + '-' + item.RELATION; |
| 2288 | |
| 2289 | if (tmp[key] || (relations && relations[item.RELATION] == null) || (!options.all && !item.INIT && !relations) || (relations && relations[item.RELATION] === item.TYPE)) |
| 2290 | return next(); |
| 2291 | |
| 2292 | tmp[key] = 1; |
| 2293 | |
| 2294 | self.read(item.ID, function(err, doc, linkid) { |
| 2295 | |
| 2296 | if (doc && (!classes || classes[doc.CLASS])) { |
| 2297 | |
| 2298 | count++; |
| 2299 | |
| 2300 | doc.INDEX = item.INDEX; |
| 2301 | doc.LEVEL = depth + 1; |
| 2302 | doc.NODES = []; |
| 2303 | |
| 2304 | var rel = self.$relations[item.RELATION]; |
| 2305 | |
| 2306 | if (rel) { |
| 2307 | // doc.RELATION = rel.relation; |
| 2308 | doc.RELATION = rel.name; |
| 2309 | } |
| 2310 | |
| 2311 | fil = filter.levels ? filter.levels[depth + 1] : null; |
| 2312 | |
| 2313 | if (fil) { |
| 2314 | !fil.response && (fil.response = parent.NODES); |
| 2315 | if (!framework_nosql.compare(fil, doc)) |
| 2316 | linkid = null; |
| 2317 | } else |
| 2318 | parent.NODES.push(doc); |
| 2319 | |
| 2320 | if (linkid && !tmp[linkid]) { |
| 2321 | pending.push({ id: linkid, parent: doc, depth: depth + 1 }); |