Skip to content

Commit

Permalink
Merge pull request #271 from domino14/bug/270/too_many_sql_vars
Browse files Browse the repository at this point in the history
Add a test for a big tag search, lower chunk size.
  • Loading branch information
domino14 authored Feb 20, 2018
2 parents 9b00494 + da5ee4a commit 6047491
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
44 changes: 44 additions & 0 deletions djAerolith/lib/tests/test_word_searches.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import time

from django.test import TestCase

from base.models import Lexicon, User, AlphagramTag
Expand Down Expand Up @@ -215,3 +217,45 @@ def test_more_tags(self):
self.assertEqual(qs.size(), 2)
self.assertEqual(['AEILT', 'CINOZ'], qs.alphagram_string_list())
self.assertTrue(len(qs.questions_array()[0].answers[0].definition) > 0)


class MassiveTagSearchCase(TestCase):
fixtures = [
'test/lexica.json',
'test/users.json',
'test/profiles.json'
]

def create_some_tags(self):
self.america = Lexicon.objects.get(lexiconName='America')
self.cesar = User.objects.get(username='cesar')
t = time.time()

qs = word_search([
SearchDescription.lexicon(self.america),
SearchDescription.length(8, 8),
SearchDescription.probability_range(5001, 8500),
])
logger.debug('Initial word search completed in %s seconds',
time.time() - t)
self.assertEqual(qs.size(), 3500)
# Create hella tags.
for q in qs.questions_array():
AlphagramTag.objects.create(user=self.cesar, lexicon=self.america,
tag='D4',
alphagram=q.alphagram.alphagram)
logger.debug('And time elapsed after tag creation: %s',
time.time() - t)

def test_tag_search(self):
self.create_some_tags()
t = time.time()
qs = word_search([
SearchDescription.lexicon(self.america),
SearchDescription.length(8, 8),
SearchDescription.probability_range(5001, 7500),
SearchDescription.tags(['D4'], self.cesar),
])
logger.debug('Tag search completed in %s seconds', time.time() - t)
self.assertEqual(qs.size(), 2500)

18 changes: 9 additions & 9 deletions djAerolith/lib/word_db_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


logger = logging.getLogger(__name__)
MAX_CHUNK_SIZE = 999
MAX_CHUNK_SIZE = 950


class BadInput(Exception):
Expand All @@ -32,7 +32,7 @@ def stdout_encode(u, default='UTF8'):
return u.encode(default)


class Word(object):
class Word:
def __init__(self, word, alphagram=None, definition=None, front_hooks=None,
back_hooks=None, inner_front_hook=None, inner_back_hook=None,
lexicon_symbols=None):
Expand All @@ -56,7 +56,7 @@ def __eq__(self, other):
return self.word == other.word


class Alphagram(object):
class Alphagram:
def __init__(self, alphagram, probability=None, combinations=None):
self.alphagram = alphagram
self.probability = probability
Expand All @@ -76,7 +76,7 @@ def __str__(self):
return '{%s} (%s)' % (self.alphagram, self.probability)


class Questions(object):
class Questions:
def __init__(self):
self.questions = []
self.build_mode = False
Expand Down Expand Up @@ -145,7 +145,7 @@ def __str__(self):
return '{<Questions %s>}' % self.questions


class Question(object):
class Question:
def __init__(self, alphagram=None, answers=None):
"""
alphagram - An Alphagram object.
Expand Down Expand Up @@ -195,7 +195,7 @@ def __str__(self):
self.answers)


class WordDB(object):
class WordDB:
"""
A database of words/definitions/alphagrams, created by the
word_db_creator Go program.
Expand Down Expand Up @@ -427,7 +427,7 @@ def process_question_query(self, rows):
return qs


class WhereClause(object):
class WhereClause:
template = '{table}.{column} {condition}'
CONDITION_BETWEEN = 'between'
CONDITION_IN = 'in'
Expand Down Expand Up @@ -500,7 +500,7 @@ def render(self):
condition=condition), bind_params)


class Query(object):
class Query:
""" A query is a single word lookup SQL query, with bind parameters. """
query_template = """
SELECT lexicon_symbols, definition, front_hooks, back_hooks,
Expand Down Expand Up @@ -532,7 +532,7 @@ def __str__(self):
query=self.query_string, bind_params=self.bind_params)


class QueryGenerator(object):
class QueryGenerator:
""" Generate the query based on passed-in parameters. """
LISTING_DESCRIPTIONS = [
SearchDescription.PROB_LIST, SearchDescription.ALPHAGRAM_LIST,
Expand Down

0 comments on commit 6047491

Please sign in to comment.