mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-15 00:43:01 -06:00
Database updates (#144)
* start moving some database stuff around * continue moving db stuff around * more fiddling * more updates * and some more * and yet more * i broke SOMETHING but what, it's a mystery * tidy up * vendor ttlcache * use ttlcache * fix up some tests * rename some stuff * little reminder * some more updates
This commit is contained in:
parent
ce190d867c
commit
4920229a3b
164 changed files with 4850 additions and 2617 deletions
71
vendor/github.com/ReneKroon/ttlcache/priority_queue.go
generated
vendored
Normal file
71
vendor/github.com/ReneKroon/ttlcache/priority_queue.go
generated
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
package ttlcache
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
)
|
||||
|
||||
func newPriorityQueue() *priorityQueue {
|
||||
queue := &priorityQueue{}
|
||||
heap.Init(queue)
|
||||
return queue
|
||||
}
|
||||
|
||||
type priorityQueue struct {
|
||||
items []*item
|
||||
}
|
||||
|
||||
func (pq *priorityQueue) update(item *item) {
|
||||
heap.Fix(pq, item.queueIndex)
|
||||
}
|
||||
|
||||
func (pq *priorityQueue) push(item *item) {
|
||||
heap.Push(pq, item)
|
||||
}
|
||||
|
||||
func (pq *priorityQueue) pop() *item {
|
||||
if pq.Len() == 0 {
|
||||
return nil
|
||||
}
|
||||
return heap.Pop(pq).(*item)
|
||||
}
|
||||
|
||||
func (pq *priorityQueue) remove(item *item) {
|
||||
heap.Remove(pq, item.queueIndex)
|
||||
}
|
||||
|
||||
func (pq priorityQueue) Len() int {
|
||||
length := len(pq.items)
|
||||
return length
|
||||
}
|
||||
|
||||
// Less will consider items with time.Time default value (epoch start) as more than set items.
|
||||
func (pq priorityQueue) Less(i, j int) bool {
|
||||
if pq.items[i].expireAt.IsZero() {
|
||||
return false
|
||||
}
|
||||
if pq.items[j].expireAt.IsZero() {
|
||||
return true
|
||||
}
|
||||
return pq.items[i].expireAt.Before(pq.items[j].expireAt)
|
||||
}
|
||||
|
||||
func (pq priorityQueue) Swap(i, j int) {
|
||||
pq.items[i], pq.items[j] = pq.items[j], pq.items[i]
|
||||
pq.items[i].queueIndex = i
|
||||
pq.items[j].queueIndex = j
|
||||
}
|
||||
|
||||
func (pq *priorityQueue) Push(x interface{}) {
|
||||
item := x.(*item)
|
||||
item.queueIndex = len(pq.items)
|
||||
pq.items = append(pq.items, item)
|
||||
}
|
||||
|
||||
func (pq *priorityQueue) Pop() interface{} {
|
||||
old := pq.items
|
||||
n := len(old)
|
||||
item := old[n-1]
|
||||
item.queueIndex = -1
|
||||
pq.items = old[0 : n-1]
|
||||
return item
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue