diff --git a/test/site_test.py b/test/site_test.py index e0047d4..66f60a5 100644 --- a/test/site_test.py +++ b/test/site_test.py @@ -349,3 +349,6 @@ def paged(limit=10): for log in get(updated_since=updated_pivot)[0]: assert log['updated'] > updated_pivot + + for log in get(include_dupes='no')[0]: + assert log['duplicate_of'] is None diff --git a/trends/site/api.py b/trends/site/api.py index ad67420..3e2203c 100644 --- a/trends/site/api.py +++ b/trends/site/api.py @@ -36,10 +36,12 @@ def next_page(rows): @api.route('/logs') def logs(): - if resp := logs_last_modified(): + dupes = flask.request.args.get('include_dupes', 'yes', str) == 'yes' + if resp := logs_last_modified(dupes): return resp + view = flask.request.args.get('view', 'basic', str) - logs = [dict(log) for log in get_logs(view)] + logs = [dict(log) for log in get_logs(view, dupes)] return flask.jsonify(logs=logs, next_page=next_page(logs)) @api.route('/maps') diff --git a/trends/site/common.py b/trends/site/common.py index bedaad0..7278951 100644 --- a/trends/site/common.py +++ b/trends/site/common.py @@ -6,10 +6,12 @@ from .util import get_db, get_filter_params, get_filter_clauses, get_order, get_pagination, \ last_modified -def logs_last_modified(): +def logs_last_modified(dupes): filters = get_filter_params() filter_clauses = get_filter_clauses(filters, 'title', 'formatd', 'mapid', 'time', 'logid', 'updated', 'league') + if not dupes: + filter_clauses += "\nAND duplicate_of ISNULL" db = get_db() cur = db.cursor() @@ -34,11 +36,14 @@ def logs_last_modified(): cur.execute(query, filters) return last_modified(cur.fetchone()[0]) -def get_logs(view): +def get_logs(view, dupes): limit, offset = get_pagination() filters = get_filter_params() filter_clauses = get_filter_clauses(filters, 'title', 'format', 'map', 'time', 'logid', 'updated', league='log.league') + if not dupes: + filter_clauses += "\nAND duplicate_of ISNULL" + order, order_clause = get_order({ 'logid': "logid", 'duration': "duration", diff --git a/trends/site/root.py b/trends/site/root.py index 020d18a..85299dc 100644 --- a/trends/site/root.py +++ b/trends/site/root.py @@ -155,9 +155,9 @@ def leaderboard(): @root.route('/logs') def logs(): - if resp := logs_last_modified(): + if resp := logs_last_modified(True): return resp - return flask.render_template("logs.html", logs=get_logs('basic').fetchall()) + return flask.render_template("logs.html", logs=get_logs('basic', True).fetchall()) @root.route('/log') def log_form(): diff --git a/trends/site/templates/api.html b/trends/site/templates/api.html index 4912a62..5757297 100644 --- a/trends/site/templates/api.html +++ b/trends/site/templates/api.html @@ -358,6 +358,14 @@
+ Include duplicate logs in the output. If {{ pre("yes") }}, then + {{ pre("duplicate_of") }} may be non-{{ pre("null") }}. If {{ pre("no") }}, + then such logs will be not be included with the results. +
+