summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher/getLinks.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/searcher/getLinks.lua')
-rw-r--r--server-beta/src/searcher/getLinks.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/server-beta/src/searcher/getLinks.lua b/server-beta/src/searcher/getLinks.lua
new file mode 100644
index 00000000..32b29be1
--- /dev/null
+++ b/server-beta/src/searcher/getLinks.lua
@@ -0,0 +1,32 @@
+local guide = require 'parser.guide'
+local searcher = require 'searcher.searcher'
+
+local function getLinks(root)
+ local cache = {}
+ guide.eachSourceType(root, 'call', function (info)
+ local uris = searcher.getLinkUris(info.source)
+ if uris then
+ for i = 1, #uris do
+ local uri = uris[i]
+ cache[uri] = true
+ end
+ end
+ end)
+ return cache
+end
+
+function searcher.getLinks(source)
+ source = guide.getRoot(source)
+ local cache = searcher.cache.getLinks[source]
+ if cache ~= nil then
+ return cache
+ end
+ local unlock = searcher.lock('getLinks', source)
+ if not unlock then
+ return nil
+ end
+ cache = getLinks(source)
+ searcher.cache.getLinks[source] = cache or false
+ unlock()
+ return cache
+end