-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full-text search for commits for PerfCompare using SearchVector (#8533)
* add searchvector to commit table and index using GIN * add ordering by push time and set result limit to 200 * add test for new search functionality * handle duplicate revisions from different projects * resolve migration conflict * resolve migration issues * resolve merge conflicts * add limit to comments filed in searchh vector * update index to have subtr for comments
- Loading branch information
Showing
5 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
from tests.conftest import IS_WINDOWS | ||
from treeherder.etl.push import store_push_data | ||
from treeherder.model.models import FailureClassification, JobNote, Push | ||
from treeherder.model.models import Commit, FailureClassification, JobNote, Push | ||
from treeherder.webapp.api import utils | ||
|
||
|
||
|
@@ -379,6 +379,93 @@ def test_push_author_contains(client, test_repository): | |
assert results[0]["id"] == 3 | ||
|
||
|
||
def test_push_search(client, test_repository): | ||
""" | ||
Test the search parameter for filtering by Commit fields: revision, author, comments. | ||
""" | ||
now = datetime.datetime.now() | ||
push1 = Push.objects.create( | ||
repository=test_repository, | ||
revision="1234abcd", | ||
author="[email protected]", | ||
time=now, | ||
) | ||
push2 = Push.objects.create( | ||
repository=test_repository, | ||
revision="2234abcd", | ||
author="[email protected]", | ||
time=now + datetime.timedelta(seconds=1), | ||
) | ||
push3 = Push.objects.create( | ||
repository=test_repository, | ||
revision="3234abcd", | ||
author="[email protected]", | ||
time=now + datetime.timedelta(seconds=2), | ||
) | ||
|
||
# Add Commit objects linked to the Push objects | ||
Commit.objects.create( | ||
push=push1, revision="1234abcd", author="kaz <[email protected]>", comments="Initial commit" | ||
) | ||
Commit.objects.create( | ||
push=push2, revision="2234abcd", author="foo <[email protected]>", comments="Bug 12345567 - fix" | ||
) | ||
Commit.objects.create( | ||
push=push3, | ||
revision="3234abcd", | ||
author="quxzan <qux@bar>.com", | ||
comments="Bug 12345567 - Feature added", | ||
) | ||
|
||
# Test search by comments | ||
resp = client.get( | ||
reverse("push-list", kwargs={"project": test_repository.name}) + "?search=bug" | ||
) | ||
assert resp.status_code == 200 | ||
|
||
results = resp.json()["results"] | ||
assert len(results) == 2 | ||
assert set([result["id"] for result in results]) == set([3, 2]) | ||
|
||
# Test search by bug number | ||
resp = client.get( | ||
reverse("push-list", kwargs={"project": test_repository.name}) + "?search=12345567" | ||
) | ||
assert resp.status_code == 200 | ||
|
||
results = resp.json()["results"] | ||
assert len(results) == 2 | ||
assert set([result["id"] for result in results]) == set([3, 2]) | ||
|
||
# Test search by author | ||
resp = client.get( | ||
reverse("push-list", kwargs={"project": test_repository.name}) + "?search=foo" | ||
) | ||
assert resp.status_code == 200 | ||
|
||
results = resp.json()["results"] | ||
assert len(results) == 1 | ||
assert results[0]["id"] == push2.id | ||
|
||
# Test search by revision | ||
resp = client.get( | ||
reverse("push-list", kwargs={"project": test_repository.name}) + "?search=3234abcd" | ||
) | ||
assert resp.status_code == 200 | ||
|
||
results = resp.json()["results"] | ||
assert len(results) == 1 | ||
assert results[0]["id"] == push3.id | ||
|
||
# Test empty search input | ||
resp = client.get(reverse("push-list", kwargs={"project": test_repository.name}) + "?search=") | ||
assert resp.status_code == 200 | ||
|
||
results = resp.json()["results"] | ||
assert len(results) == 3 | ||
assert set([result["id"] for result in results]) == set([3, 2, 1]) | ||
|
||
|
||
def test_push_reviewbot(client, test_repository): | ||
""" | ||
test the reviewbot parameter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
treeherder/model/migrations/0038_commit_search_vector_idx.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 5.1.5 on 2025-02-27 18:06 | ||
|
||
import django.contrib.postgres.indexes | ||
import django.contrib.postgres.search | ||
import django.db.models.functions.text | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("model", "0037_bugjobmap_internal_bug_refs"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddIndex( | ||
model_name="commit", | ||
index=django.contrib.postgres.indexes.GinIndex( | ||
django.contrib.postgres.search.SearchVector( | ||
"revision", | ||
"author", | ||
django.db.models.functions.text.Substr("comments", 1, 100000), | ||
config="english", | ||
), | ||
name="search_vector_idx", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters