Close gaping hole due to O(n!) algorithm (lol).

This commit is contained in:
Flancian 2021-02-02 01:16:40 +01:00
parent 32b57bd849
commit a96cf45bfa
1 changed files with 6 additions and 2 deletions

View File

@ -65,11 +65,15 @@ class Graph:
# Return an empty.
return Node(uri)
def existing_permutations(self, uri):
def existing_permutations(self, uri, max_length=4):
# looks up nodes matching a permutation of the tokenized uri.
#
# example use: if [[server-agora]] does not exist, serve [[agora-server]]
permutations = itertools.permutations(uri.split('-'))
#
# this is, of course, a terrible implementation and dangerous :)
# only enable up to 4 tokens as 24 permutations is manageable.
tokens = uri.split('-')
permutations = itertools.permutations(tokens, max_length)
permutations = ['-'.join(permutation) for permutation in permutations]
nodes = [node for node in G.nodes() if node.wikilink in permutations and node.subnodes]
return nodes