Show correct crash count when filtering versions

The new query should be tested with a big database to see if the performance is good enough (although I think so)

Fixes #40
parent 391e6933
# Changelog
## Version x.x.x
* Add: `-config`-flag to specify config file when running CrashDragon
* Change: Now gracefully shutting down on `SIGINT` (See #25)
* Fix: Show correct crash counts when filtered by version (See #40)
## Version 1.1.1
* Add: `govendor sync` step to update guide
* Change: Updated GROM to current master
* Change: Updated GORM to current master
* Fix: Crash-Version-Association
* Fix: Correctly install stylesheet
......
......@@ -84,10 +84,9 @@ type Crash struct {
DeletedAt *time.Time
Signature string
AllCrashCount uint
WinCrashCount uint
MacCrashCount uint
LinCrashCount uint
AllCrashCount uint `gorm:"-"`
WinCrashCount uint `gorm:"-"`
MacCrashCount uint `gorm:"-"`
Reports []Report
Comments []Comment
......
BEGIN TRANSACTION;
-- Drop no longer needed xxx_crash_count from crashes
ALTER TABLE crashes DROP COLUMN IF EXISTS all_crash_count, DROP COLUMN IF EXISTS win_crash_count, DROP COLUMN IF EXISTS mac_crash_count, DROP COLUMN IF EXISTS lin_crash_count;
END TRANSACTION;
......@@ -194,11 +194,6 @@ func processCrash(tx *gorm.DB, Report database.Report, reprocess bool, Crash *da
Crash.FirstReported = Report.CreatedAt
Crash.Signature = Report.Signature
Crash.AllCrashCount = 0
Crash.WinCrashCount = 0
Crash.MacCrashCount = 0
Crash.LinCrashCount = 0
Crash.ProductID = Report.ProductID
Crash.Fixed = false
......@@ -208,15 +203,6 @@ func processCrash(tx *gorm.DB, Report database.Report, reprocess bool, Crash *da
}
if !reprocess || Report.CrashID == uuid.Nil {
Crash.LastReported = Report.CreatedAt
Crash.AllCrashCount++
if Report.Os == "Windows NT" {
Crash.WinCrashCount++
} else if Report.Os == "Linux" {
Crash.LinCrashCount++
} else if Report.Os == "Mac OS X" {
Crash.MacCrashCount++
}
tx.Save(&Crash)
}
tx.Model(&Crash).Related(&Crash.Versions, "Versions")
......
......@@ -59,8 +59,10 @@ func GetCrashes(c *gin.Context) {
}
all, ver := GetVersionCookie(c)
if !all {
query = query.Select("*, (?) AS all_crash_count, (?) AS win_crash_count, (?) AS mac_crash_count", database.Db.Table("reports").Select("count(*)").Where("crash_id = crashes.id AND version_id = ?", ver.ID).QueryExpr(), database.Db.Table("reports").Select("count(*)").Where("crash_id = crashes.id AND version_id = ? AND os = 'Windows NT'", ver.ID).QueryExpr(), database.Db.Table("reports").Select("count(*)").Where("crash_id = crashes.id AND version_id = ? AND os = 'Mac OS X'", ver.ID).QueryExpr())
query = query.Where("id in (?)", database.Db.Table("crash_versions").Select("crash_id").Where("version_id = ?", ver.ID).QueryExpr())
//query = query.Model(&ver).Association("Versions")
} else {
query = query.Select("*, (?) AS all_crash_count, (?) AS win_crash_count, (?) AS mac_crash_count", database.Db.Table("reports").Select("count(*)").Where("crash_id = crashes.id").QueryExpr(), database.Db.Table("reports").Select("count(*)").Where("crash_id = crashes.id AND os = 'Windows NT'").QueryExpr(), database.Db.Table("reports").Select("count(*)").Where("crash_id = crashes.id AND os = 'Mac OS X'").QueryExpr())
}
offset, err := strconv.Atoi(c.DefaultQuery("offset", "0"))
if err != nil {
......
......@@ -10,8 +10,7 @@
<th scope="col">Signature</th>
<th scope="col">All</th>
<th scope="col">Windows</th>
<th scope="col">Mac OS X</th>
<th scope="col">Linux</th>
<th scope="col">macOS</th>
<th scope="col">First reported</th>
<th scope="col">Last reported</th>
</tr>
......@@ -24,7 +23,6 @@
<td>{{ .AllCrashCount }}</td>
<td>{{ .WinCrashCount }}</td>
<td>{{ .MacCrashCount }}</td>
<td>{{ .LinCrashCount }}</td>
<td>{{ .FirstReported.Format "02. Jan. 2006 15:04:05 UTC" }}</td>
<td>{{ .LastReported.Format "02. Jan. 2006 15:04:05 UTC" }}</td>
</tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment