Skip to content

Commit

Permalink
Add some indexes for JSON fields, fix numerous bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
john-dupuy committed Oct 2, 2020
1 parent 32ef735 commit 47b1d7a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_widget_config_list(filter_=None, page=1, page_size=25):
offset = (page * page_size) - page_size
total_items = query.count()
total_pages = (total_items // page_size) + (1 if total_items % page_size > 0 else 0)
widgets = query.order_by(WidgetConfig.weight.desc()).offset(offset).limit(page_size)
widgets = query.order_by(WidgetConfig.weight.asc()).offset(offset).limit(page_size)
return {
"widgets": [widget.to_dict() for widget in widgets],
"pagination": {
Expand Down
2 changes: 2 additions & 0 deletions backend/ibutsu_server/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def string_to_column(field, model):
if idx == 0:
continue
column = column[part]
if field not in ARRAY_FIELDS:
column = column.as_string()
else:
column = getattr(model, field)
return column
Expand Down
20 changes: 15 additions & 5 deletions backend/ibutsu_server/scripts/mongo2postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
UUID_1_EPOCH = datetime(1582, 10, 15, tzinfo=timezone.utc)
UUID_TICKS = 10000000
UUID_VARIANT_1 = 0b1000000000000000
ROWS_TO_COMMIT_AT_ONCE = 10000
ROWS_TO_COMMIT_AT_ONCE = 1000
MONTHS_TO_KEEP = 1
# To avoid foreign key constraints, just shift the range of artifacts to keep a bit
ARTIFACT_MONTHS_TO_KEEP = 0.75 * MONTHS_TO_KEEP
Expand Down Expand Up @@ -69,10 +69,18 @@

# json indexes for the tables
INDEXES = {
# "results": [
# ],
# "runs": [
# ],
"results": [
"CREATE INDEX ix_results_jenkins_job_name ON results((data->'jenkins'->>'job_name'));",
"CREATE INDEX ix_results_jenkins_build_number "
"ON results((data->'jenkins'->>'build_number'));",
"CREATE INDEX ix_results_classification ON results((data->>'classification'));",
"CREATE INDEX ix_results_assignee ON results((data->>'assignee'));",
"CREATE INDEX ix_results_exception_name ON results((data->>'exception_name'));",
],
"runs": [
"CREATE INDEX ix_runs_jenkins_job_name ON runs((data->'jenkins'->>'job_name'));"
"CREATE INDEX ix_runs_jenkins_build_number ON runs((data->'jenkins'->>'build_number'));"
],
}


Expand Down Expand Up @@ -195,6 +203,8 @@ def migrate_table(collection, Model, vprint, filter_=None):
if row.get("params") and row["params"].get("sort_field"):
# we no longer use this field
row["params"].pop("sort_field")
if row.get("params") and row["params"].get("group_field") == "metadata.component":
row["params"]["group_field"] = "component"

obj = Model.from_dict(**row)
session.add(obj)
Expand Down
7 changes: 4 additions & 3 deletions backend/ibutsu_server/widgets/jenkins_heatmap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ibutsu_server.db.base import Float
from ibutsu_server.db.base import Integer
from ibutsu_server.db.base import session
from ibutsu_server.db.models import Run
from ibutsu_server.filters import apply_filters
Expand Down Expand Up @@ -42,7 +43,7 @@ def _get_builds(job_name, builds, project=None):

# create the query
query = (
session.query(group_field.label("build_number"))
session.query(group_field.cast(Integer).label("build_number"))
.group_by("build_number")
.order_by(desc("build_number"))
)
Expand All @@ -51,7 +52,7 @@ def _get_builds(job_name, builds, project=None):
query = apply_filters(query, filters, Run)

# make the query
return [build_number[0] for build_number in query.limit(builds)]
return [str(build_number[0]) for build_number in query.limit(builds)]


def _get_heatmap(job_name, builds, group_field, count_skips, project=None):
Expand All @@ -67,7 +68,7 @@ def _get_heatmap(job_name, builds, group_field, count_skips, project=None):
f"{group_field}@y",
]
if project:
filters.append(f"metadata.project={project}")
filters.append(f"project_id={project}")

# generate the group_fields
group_field = string_to_column(group_field, Run)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class App extends React.Component {
let params = {'filter': ['type=view', 'navigable=true']};
let project = getActiveProject();
if (project) {
params['filter'].push('project=' + project.id);
params['filter'].push('project_id=' + project.id);
}
fetch(buildUrl(Settings.serverUrl + '/widget-config', params))
.then(response => response.json())
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Dashboard extends React.Component {
let params = {"type": "widget"};
let project = getActiveProject();
if (project) {
params['filter'] = 'project=' + project.id;
params['filter'] = 'project_id=' + project.id;
}
fetch(buildUrl(Settings.serverUrl + '/widget-config', params))
.then(response => response.json())
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export class Run extends React.Component {
}

getResultsForTree(page) {
let params = {filter: 'metadata.run=' + this.state.id};
let params = {filter: 'run_id=' + this.state.id};
params['pageSize'] = 500;
params['page'] = page;
fetch(buildUrl(Settings.serverUrl + '/result', params))
Expand Down

0 comments on commit 47b1d7a

Please sign in to comment.