Use a real reverse function
This commit is contained in:
parent
6756527f31
commit
912e1322da
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -202,7 +203,7 @@ func (b *memoryBackend) TimelineGet(after, before, channel string) microsub.Time
|
||||||
return strings.Compare(timeA, timeB) > 0
|
return strings.Compare(timeA, timeB) > 0
|
||||||
})
|
})
|
||||||
|
|
||||||
items := sort.Reverse(items)
|
reverseSlice(items)
|
||||||
|
|
||||||
return microsub.Timeline{
|
return microsub.Timeline{
|
||||||
Paging: microsub.Pagination{},
|
Paging: microsub.Pagination{},
|
||||||
|
|
@ -210,6 +211,15 @@ func (b *memoryBackend) TimelineGet(after, before, channel string) microsub.Time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//panic if s is not a slice
|
||||||
|
func reverseSlice(s interface{}) {
|
||||||
|
size := reflect.ValueOf(s).Len()
|
||||||
|
swap := reflect.Swapper(s)
|
||||||
|
for i, j := 0, size-1; i < j; i, j = i+1, j-1 {
|
||||||
|
swap(i, j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *memoryBackend) checkRead(channel string, uid string) bool {
|
func (b *memoryBackend) checkRead(channel string, uid string) bool {
|
||||||
args := redis.Args{}.Add(fmt.Sprintf("timeline:%s:read", channel)).Add(uid)
|
args := redis.Args{}.Add(fmt.Sprintf("timeline:%s:read", channel)).Add(uid)
|
||||||
member, err := redis.Bool(b.Redis.Do("SISMEMBER", args...))
|
member, err := redis.Bool(b.Redis.Do("SISMEMBER", args...))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user