Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove invalid database names from dropdown suggestions #24

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions quarry/web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,28 @@ def pref_set(key, value) -> Union[Tuple[str, int], Tuple[Response, int]]:
@api_blueprint.route("/api/dbs")
def get_dbs() -> Response:
known_dbs = (
g.conn.session.query(QueryRevision.query_database).distinct().all()
g.conn.session.query(QueryRevision.query_database)
.join(QueryRun, QueryRevision.id == QueryRun.query_rev_id)
.filter(QueryRun.extra_info.notlike('{"error%'))
.filter(QueryRevision.query_database.isnot(None))
.distinct()
.all()
)
return Response(
response = Response(
json.dumps(
{
"dbs": list(
set(
db_result[-1].strip().rstrip(";")
db_result[-1].strip()
for db_result in known_dbs
# the db data might be NULL, empty strings or spaces+tabs only so this helps a bit to show only
# likely names
if db_result[-1] and db_result[-1].strip()
if db_result[-1]
)
)
}
},
# Remove spaces to reduce response size
separators=(",", ":"),
),
mimetype="application/json",
)
response.headers["Cache-Control"] = "max-age=3600, public"
return response
Loading