Allow showing a group by the uuid of any of it's individual crash
This removes the dependency on insertion order.
Also split Group::stats_by_product_and_version from get
--- a/lib/CrashTest/Controller/CrashGroups.pm Sun Feb 14 23:15:36 2016 +0100
+++ b/lib/CrashTest/Controller/CrashGroups.pm Sun Feb 14 23:20:44 2016 +0100
@@ -41,8 +41,8 @@
my $uuid = $self->param('uuid');
my $group = $self->app->crash_groups->get($uuid);
- $self->stash(group => $group->{group});
- $self->stash(stats_by_product_and_version => $group->{stats_by_product_and_version});
+ $self->stash(group => $self->app->crash_groups->get($uuid));
+ $self->stash(stats_by_product_and_version => $self->app->crash_groups->stats_by_product_and_version($uuid));
my $page = 1;
my $crashs_per_page = 20;
@@ -51,9 +51,9 @@
my $search = $self->req->param('search');
if(defined($search) && $search ne "") {
- $search .= " AND " . "group_id=$group->{group}->{id}";
+ $search .= " AND " . "group_id=$group->{id}";
} else {
- $search = "group_id=$group->{group}->{id}";
+ $search = "group_id=$group->{id}";
}
my ($results, $pager) = $self->crash_reports->index($page, $crashs_per_page, $search);
--- a/lib/CrashTest/Model/CrashGroup.pm Sun Feb 14 23:15:36 2016 +0100
+++ b/lib/CrashTest/Model/CrashGroup.pm Sun Feb 14 23:20:44 2016 +0100
@@ -28,4 +28,10 @@
return $self->app->storage->first("CrashGroup::get", $uuid);
}
+sub stats_by_product_and_version {
+ my ($self, $uuid) = @_;
+
+ return $self->app->storage->first("CrashGroup::stats_by_product_and_version", $uuid);
+}
+
1;
--- a/lib/CrashTest/Plugin/Storage/Sql/Model/CrashGroup.pm Sun Feb 14 23:15:36 2016 +0100
+++ b/lib/CrashTest/Plugin/Storage/Sql/Model/CrashGroup.pm Sun Feb 14 23:20:44 2016 +0100
@@ -108,19 +108,17 @@
my ($self, $uuid) = @_;
my $result = $self->db->query("
- SELECT * FROM crash_groups WHERE uuid = ?
+ SELECT * FROM crash_groups WHERE id = (SELECT crash_group_id FROM crash_reports WHERE uuid = ?)
",
$uuid
)->hash;
- return {
- group => $result,
- stats_by_product_and_version => $self->_stats_by_product_and_version($result->{id})
- };
+ return $result;
}
-sub _stats_by_product_and_version {
- my ($self, $crash_id) = @_;
+sub stats_by_product_and_version {
+ my ($self, $group_uuid) = @_;
+
my $results = $self->db->query("
SELECT
name AS product_name,
@@ -128,11 +126,13 @@
count(*) AS crash_count
FROM crash_reports
JOIN products ON product_id = products.id
- WHERE crash_group_id = ?
+ WHERE crash_group_id = (
+ SELECT crash_group_id FROM crash_reports WHERE uuid = ?
+ )
GROUP BY product_name, version
ORDER BY crash_count DESC, product_name, version;
",
- $crash_id
+ $group_uuid
)->hashes;
return $results;
}