2018-08-06 21:31:20 +03:00
|
|
|
package bug
|
|
|
|
|
|
|
|
type BugsByCreationTime []*Bug
|
|
|
|
|
|
|
|
func (b BugsByCreationTime) Len() int {
|
|
|
|
return len(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b BugsByCreationTime) Less(i, j int) bool {
|
|
|
|
if b[i].createTime < b[j].createTime {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if b[i].createTime > b[j].createTime {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the logical clocks are identical, that means we had a concurrent
|
|
|
|
// edition. In this case we rely on the timestamp. While the timestamp might
|
|
|
|
// be incorrect due to a badly set clock, the drift in sorting is bounded
|
2018-08-07 15:57:12 +03:00
|
|
|
// by the first sorting using the logical clock. That means that if users
|
2018-08-06 21:31:20 +03:00
|
|
|
// synchronize their bugs regularly, the timestamp will rarely be used, and
|
|
|
|
// should still provide a kinda accurate sorting when needed.
|
2018-08-15 23:01:45 +03:00
|
|
|
return b[i].FirstOp().Time().Before(b[j].FirstOp().Time())
|
2018-08-06 21:31:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b BugsByCreationTime) Swap(i, j int) {
|
|
|
|
b[i], b[j] = b[j], b[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
type BugsByEditTime []*Bug
|
|
|
|
|
|
|
|
func (b BugsByEditTime) Len() int {
|
|
|
|
return len(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b BugsByEditTime) Less(i, j int) bool {
|
|
|
|
if b[i].editTime < b[j].editTime {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if b[i].editTime > b[j].editTime {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the logical clocks are identical, that means we had a concurrent
|
|
|
|
// edition. In this case we rely on the timestamp. While the timestamp might
|
|
|
|
// be incorrect due to a badly set clock, the drift in sorting is bounded
|
2018-08-07 15:57:12 +03:00
|
|
|
// by the first sorting using the logical clock. That means that if users
|
2018-08-06 21:31:20 +03:00
|
|
|
// synchronize their bugs regularly, the timestamp will rarely be used, and
|
|
|
|
// should still provide a kinda accurate sorting when needed.
|
2018-08-15 23:01:45 +03:00
|
|
|
return b[i].LastOp().Time().Before(b[j].LastOp().Time())
|
2018-08-06 21:31:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b BugsByEditTime) Swap(i, j int) {
|
|
|
|
b[i], b[j] = b[j], b[i]
|
|
|
|
}
|