Improve message generation speed
This moves most of the "heavy lifting" of the database queries into sqlite itself, which is much faster at it.
This commit is contained in:
parent
e5f63abff2
commit
7a4e3de976
1 changed files with 7 additions and 7 deletions
|
@ -28,10 +28,10 @@ async def getNoun(self, words, c):
|
||||||
|
|
||||||
shared.db['remsg'].insert_ignore(dict(noun=oldnoun,msg=' '.join(words)),['id'])
|
shared.db['remsg'].insert_ignore(dict(noun=oldnoun,msg=' '.join(words)),['id'])
|
||||||
|
|
||||||
nouns = [i['word'] for i in shared.db['noun'].find()]
|
nouns = shared.db['noun']
|
||||||
out = {}
|
out = {}
|
||||||
for i in words:
|
for i in words:
|
||||||
out[i] = nouns.count(i)
|
out[i] = nouns.count(word=i)
|
||||||
noun = min(out, key=out.get)
|
noun = min(out, key=out.get)
|
||||||
|
|
||||||
conversation = shared.db['conver']
|
conversation = shared.db['conver']
|
||||||
|
@ -51,13 +51,13 @@ async def genOut(self, noun):
|
||||||
if len(oldresponses) > 0:
|
if len(oldresponses) > 0:
|
||||||
return random.choice(oldresponses).split(' ')
|
return random.choice(oldresponses).split(' ')
|
||||||
prew = shared.db['prew']
|
prew = shared.db['prew']
|
||||||
beg = [ i['word'] for i in shared.db['beg'].find() ]
|
beg = shared.db['beg']
|
||||||
end = [ i['word'] for i in shared.db['end'].find() ]
|
end = shared.db['end']
|
||||||
nouns = [i['word'] for i in shared.db['noun'].find()]
|
nouns = shared.db['noun']
|
||||||
iter=0
|
iter=0
|
||||||
coun=0
|
coun=0
|
||||||
out = [noun]
|
out = [noun]
|
||||||
while (out[0] not in beg or nouns.count(out[0])-1 > iter * shared.enmul) and iter < 7:
|
while (beg.find_one(word=out[0]) is None or nouns.count(word=out[0])-1 > iter * shared.enmul) and iter < 7:
|
||||||
try:
|
try:
|
||||||
out = [ random.choice(list(prew.find(pro=out[0])))['pre'] ] + out
|
out = [ random.choice(list(prew.find(pro=out[0])))['pre'] ] + out
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -65,7 +65,7 @@ async def genOut(self, noun):
|
||||||
iter += 1
|
iter += 1
|
||||||
coun += 1
|
coun += 1
|
||||||
iter = 0
|
iter = 0
|
||||||
while (out[-1] not in end or nouns.count(out[-1])-1 > iter * shared.enmul) and iter < 7:
|
while (end.find_one(word=out[-1]) is None or nouns.count(word=out[-1])-1 > iter * shared.enmul) and iter < 7:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
out.append(random.choice(list(prew.find(pre=out[-1])))['pro'])
|
out.append(random.choice(list(prew.find(pre=out[-1])))['pro'])
|
||||||
|
|
Loading…
Reference in a new issue