Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ordering by push time and set result limit to 200
Browse files Browse the repository at this point in the history
Netacci committed Jan 27, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent df83881 commit f6af36a
Showing 2 changed files with 19 additions and 10 deletions.
5 changes: 4 additions & 1 deletion treeherder/model/models.py
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@
import newrelic.agent
from django.contrib.auth.models import User
from django.contrib.postgres.indexes import GinIndex
from django.contrib.postgres.search import SearchVector, TrigramSimilarity
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist
from django.core.validators import MinLengthValidator
from django.db import models, transaction
from django.db.models import Count, Max, Min, Q, Subquery
from django.contrib.postgres.search import TrigramSimilarity, SearchVector
from django.db.utils import ProgrammingError
from django.forms import model_to_dict
from django.utils import timezone
@@ -195,8 +195,11 @@ class Meta:
name="search_vector_idx",
),
]

def __str__(self):
return f"{self.push.repository.name} {self.revision}"


class MachinePlatform(models.Model):
id = models.AutoField(primary_key=True)
os_name = models.CharField(max_length=25)
24 changes: 15 additions & 9 deletions treeherder/webapp/api/push.py
Original file line number Diff line number Diff line change
@@ -3,13 +3,14 @@

import newrelic.agent
from cache_memoize import cache_memoize
from django.contrib.postgres.search import SearchQuery, SearchVector
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_404_NOT_FOUND

from treeherder.log_parser.failureline import get_group_results
from treeherder.model.models import Job, JobType, Push, Repository, Commit
from treeherder.model.models import Commit, Job, JobType, Push, Repository
from treeherder.push_health.builds import get_build_failures
from treeherder.push_health.compare import get_commit_history
from treeherder.push_health.linting import get_lint_failures
@@ -22,7 +23,6 @@
from treeherder.webapp.api.serializers import PushSerializer
from treeherder.webapp.api.utils import to_datetime, to_timestamp

from django.contrib.postgres.search import SearchVector, SearchQuery
logger = logging.getLogger(__name__)


@@ -71,13 +71,19 @@ def list(self, request, project):
pushes = pushes.filter(repository=repository)

search_param = filter_params.get("search")
if search_param:
filtered_commits = Commit.objects.annotate(
search=SearchVector("revision", "author", "comments", config="english")
).filter(
search=SearchQuery(search_param, config="english")
).values_list("push_id", flat=True)
pushes = pushes.filter(id__in=filtered_commits)
if search_param:
filtered_commits = (
Commit.objects.annotate(
search=SearchVector("revision", "author", "comments", config="english")
)
.filter(
search=SearchQuery(search_param, config="english")
# Get most recent results and limit result to 200
)
.order_by("-push__time")[:200]
.values_list("push_id", flat=True)
)
pushes = pushes.filter(id__in=filtered_commits)
for param, value in meta.items():
if param == "fromchange":
revision_field = "revision__startswith" if len(value) < 40 else "revision"

0 comments on commit f6af36a

Please sign in to comment.