server/posts: optimize 'posts around' query
This commit is contained in:
parent
0f1e234a5d
commit
36eddad424
3 changed files with 7 additions and 1 deletions
|
@ -10,6 +10,9 @@ class BaseSearchConfig(object):
|
||||||
def create_filter_query(self):
|
def create_filter_query(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def create_around_query(self):
|
||||||
|
return self.create_filter_query()
|
||||||
|
|
||||||
def create_count_query(self):
|
def create_count_query(self):
|
||||||
return self.create_filter_query()
|
return self.create_filter_query()
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,9 @@ class PostSearchConfig(BaseSearchConfig):
|
||||||
new_special_tokens.append(token)
|
new_special_tokens.append(token)
|
||||||
search_query.special_tokens = new_special_tokens
|
search_query.special_tokens = new_special_tokens
|
||||||
|
|
||||||
|
def create_around_query(self):
|
||||||
|
return db.session.query(db.Post.post_id)
|
||||||
|
|
||||||
def create_filter_query(self):
|
def create_filter_query(self):
|
||||||
return self.create_count_query() \
|
return self.create_count_query() \
|
||||||
.options(
|
.options(
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Executor(object):
|
||||||
search_query = self.parser.parse(query_text)
|
search_query = self.parser.parse(query_text)
|
||||||
self.config.on_search_query_parsed(search_query)
|
self.config.on_search_query_parsed(search_query)
|
||||||
filter_query = self.config \
|
filter_query = self.config \
|
||||||
.create_filter_query() \
|
.create_around_query() \
|
||||||
.options(sqlalchemy.orm.lazyload('*'))
|
.options(sqlalchemy.orm.lazyload('*'))
|
||||||
filter_query = self._prepare_db_query(filter_query, search_query, False)
|
filter_query = self._prepare_db_query(filter_query, search_query, False)
|
||||||
prev_filter_query = filter_query \
|
prev_filter_query = filter_query \
|
||||||
|
|
Loading…
Reference in a new issue