mirror of
https://git.nolog.cz/NoLog.cz/headline.git
synced 2025-01-31 11:53:35 +01:00
change view sql query construction
This commit is contained in:
parent
ec03dace99
commit
21ba8267f1
1 changed files with 12 additions and 6 deletions
18
view/app.py
18
view/app.py
|
@ -69,22 +69,27 @@ def index():
|
||||||
selected_feeds = request.args.getlist("feeds[]")
|
selected_feeds = request.args.getlist("feeds[]")
|
||||||
|
|
||||||
sql_select = "SELECT * FROM diffs "
|
sql_select = "SELECT * FROM diffs "
|
||||||
|
sql_select_args = []
|
||||||
sql_count = "SELECT count(*) FROM diffs "
|
sql_count = "SELECT count(*) FROM diffs "
|
||||||
|
sql_count_args = []
|
||||||
|
|
||||||
if query:
|
if query:
|
||||||
sql_part_query = f"JOIN (SELECT rowid FROM diffs_fts({query})) filter ON filter.rowid = diffs.diff_id "
|
sql_part_query = "JOIN (SELECT rowid FROM diffs_fts(?)) filter ON filter.rowid = diffs.diff_id "
|
||||||
sql_select = sql_select + sql_part_query
|
sql_select = sql_select + sql_part_query
|
||||||
|
sql_select_args.append(query)
|
||||||
sql_count = sql_count + sql_part_query
|
sql_count = sql_count + sql_part_query
|
||||||
|
sql_count_args.append(query)
|
||||||
|
|
||||||
if selected_feeds:
|
if selected_feeds:
|
||||||
feeds = str(selected_feeds).strip("[]")
|
sql_part_feeds = f"WHERE feed_name in ({','.join(['?' for _ in range(len(selected_feeds))])}) "
|
||||||
sql_part_feeds = f"WHERE feed_name in ({feeds}) "
|
|
||||||
sql_select = sql_select + sql_part_feeds
|
sql_select = sql_select + sql_part_feeds
|
||||||
|
sql_select_args += selected_feeds
|
||||||
sql_count = sql_count + sql_part_feeds
|
sql_count = sql_count + sql_part_feeds
|
||||||
|
sql_count_args += selected_feeds
|
||||||
|
|
||||||
# flask-paginate
|
# flask-paginate
|
||||||
page = request.args.get(get_page_parameter(), type=int, default=1)
|
page = request.args.get(get_page_parameter(), type=int, default=1)
|
||||||
db.execute(sql_count)
|
db.execute(sql_count, sql_count_args)
|
||||||
diff_count = db.fetchall()[0][0]
|
diff_count = db.fetchall()[0][0]
|
||||||
|
|
||||||
pagination = Pagination(
|
pagination = Pagination(
|
||||||
|
@ -94,10 +99,11 @@ def index():
|
||||||
per_page = pagination.per_page
|
per_page = pagination.per_page
|
||||||
|
|
||||||
# Create and execute final query after getting page info
|
# Create and execute final query after getting page info
|
||||||
sql_part_pagination = f"ORDER BY diff_id DESC LIMIT {per_page} OFFSET {page_skip} "
|
sql_part_pagination = "ORDER BY diff_id DESC LIMIT ? OFFSET ? "
|
||||||
sql_select = sql_select + sql_part_pagination
|
sql_select = sql_select + sql_part_pagination
|
||||||
|
sql_select_args += [per_page, page_skip]
|
||||||
print(sql_select)
|
print(sql_select)
|
||||||
db.execute(sql_select)
|
db.execute(sql_select, sql_select_args)
|
||||||
|
|
||||||
# This would be a cleaner way to do it, but I have no clue how to make it work. Giving multiple feeds to the query is just seemingly impossible in sqlite.
|
# This would be a cleaner way to do it, but I have no clue how to make it work. Giving multiple feeds to the query is just seemingly impossible in sqlite.
|
||||||
# What about switching to Elasticsearch? :)
|
# What about switching to Elasticsearch? :)
|
||||||
|
|
Loading…
Reference in a new issue