parent
c309faf79f
commit
523837910c
|
@ -38,12 +38,7 @@ func (s *DefaultLikeStore) BulkExists(ids []int, sentBy int, targetType string)
|
||||||
}
|
}
|
||||||
eids = append(eids,id)
|
eids = append(eids,id)
|
||||||
}
|
}
|
||||||
err = rows.Err()
|
return eids, rows.Err()
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return eids, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Write a test for this
|
// TODO: Write a test for this
|
||||||
|
|
|
@ -39,10 +39,10 @@ func NewMemoryPollCache(capacity int) *MemoryPollCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get fetches a poll by ID. Returns ErrNoRows if not present.
|
// Get fetches a poll by ID. Returns ErrNoRows if not present.
|
||||||
func (mus *MemoryPollCache) Get(id int) (*Poll, error) {
|
func (s *MemoryPollCache) Get(id int) (*Poll, error) {
|
||||||
mus.RLock()
|
s.RLock()
|
||||||
item, ok := mus.items[id]
|
item, ok := s.items[id]
|
||||||
mus.RUnlock()
|
s.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
|
@ -50,19 +50,19 @@ func (mus *MemoryPollCache) Get(id int) (*Poll, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BulkGet fetches multiple polls by their IDs. Indices without polls will be set to nil, so make sure you check for those, we might want to change this behaviour to make it less confusing.
|
// BulkGet fetches multiple polls by their IDs. Indices without polls will be set to nil, so make sure you check for those, we might want to change this behaviour to make it less confusing.
|
||||||
func (mus *MemoryPollCache) BulkGet(ids []int) (list []*Poll) {
|
func (s *MemoryPollCache) BulkGet(ids []int) (list []*Poll) {
|
||||||
list = make([]*Poll, len(ids))
|
list = make([]*Poll, len(ids))
|
||||||
mus.RLock()
|
s.RLock()
|
||||||
for i, id := range ids {
|
for i, id := range ids {
|
||||||
list[i] = mus.items[id]
|
list[i] = s.items[id]
|
||||||
}
|
}
|
||||||
mus.RUnlock()
|
s.RUnlock()
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUnsafe fetches a poll by ID. Returns ErrNoRows if not present. THIS METHOD IS NOT THREAD-SAFE.
|
// GetUnsafe fetches a poll by ID. Returns ErrNoRows if not present. THIS METHOD IS NOT THREAD-SAFE.
|
||||||
func (mus *MemoryPollCache) GetUnsafe(id int) (*Poll, error) {
|
func (s *MemoryPollCache) GetUnsafe(id int) (*Poll, error) {
|
||||||
item, ok := mus.items[id]
|
item, ok := s.items[id]
|
||||||
if ok {
|
if ok {
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
|
@ -70,95 +70,95 @@ func (mus *MemoryPollCache) GetUnsafe(id int) (*Poll, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set overwrites the value of a poll in the cache, whether it's present or not. May return a capacity overflow error.
|
// Set overwrites the value of a poll in the cache, whether it's present or not. May return a capacity overflow error.
|
||||||
func (mus *MemoryPollCache) Set(item *Poll) error {
|
func (s *MemoryPollCache) Set(item *Poll) error {
|
||||||
mus.Lock()
|
s.Lock()
|
||||||
user, ok := mus.items[item.ID]
|
user, ok := s.items[item.ID]
|
||||||
if ok {
|
if ok {
|
||||||
mus.Unlock()
|
s.Unlock()
|
||||||
*user = *item
|
*user = *item
|
||||||
} else if int(mus.length) >= mus.capacity {
|
} else if int(s.length) >= s.capacity {
|
||||||
mus.Unlock()
|
s.Unlock()
|
||||||
return ErrStoreCapacityOverflow
|
return ErrStoreCapacityOverflow
|
||||||
} else {
|
} else {
|
||||||
mus.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
mus.Unlock()
|
s.Unlock()
|
||||||
atomic.AddInt64(&mus.length, 1)
|
atomic.AddInt64(&s.length, 1)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds a poll to the cache, similar to Set, but it's only intended for new items. This method might be deprecated in the near future, use Set. May return a capacity overflow error.
|
// Add adds a poll to the cache, similar to Set, but it's only intended for new items. This method might be deprecated in the near future, use Set. May return a capacity overflow error.
|
||||||
// ? Is this redundant if we have Set? Are the efficiency wins worth this? Is this even used?
|
// ? Is this redundant if we have Set? Are the efficiency wins worth this? Is this even used?
|
||||||
func (mus *MemoryPollCache) Add(item *Poll) error {
|
func (s *MemoryPollCache) Add(item *Poll) error {
|
||||||
mus.Lock()
|
s.Lock()
|
||||||
if int(mus.length) >= mus.capacity {
|
if int(s.length) >= s.capacity {
|
||||||
mus.Unlock()
|
s.Unlock()
|
||||||
return ErrStoreCapacityOverflow
|
return ErrStoreCapacityOverflow
|
||||||
}
|
}
|
||||||
mus.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
mus.length = int64(len(mus.items))
|
s.length = int64(len(s.items))
|
||||||
mus.Unlock()
|
s.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUnsafe is the unsafe version of Add. May return a capacity overflow error. THIS METHOD IS NOT THREAD-SAFE.
|
// AddUnsafe is the unsafe version of Add. May return a capacity overflow error. THIS METHOD IS NOT THREAD-SAFE.
|
||||||
func (mus *MemoryPollCache) AddUnsafe(item *Poll) error {
|
func (s *MemoryPollCache) AddUnsafe(item *Poll) error {
|
||||||
if int(mus.length) >= mus.capacity {
|
if int(s.length) >= s.capacity {
|
||||||
return ErrStoreCapacityOverflow
|
return ErrStoreCapacityOverflow
|
||||||
}
|
}
|
||||||
mus.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
mus.length = int64(len(mus.items))
|
s.length = int64(len(s.items))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove removes a poll from the cache by ID, if they exist. Returns ErrNoRows if no items exist.
|
// Remove removes a poll from the cache by ID, if they exist. Returns ErrNoRows if no items exist.
|
||||||
func (mus *MemoryPollCache) Remove(id int) error {
|
func (s *MemoryPollCache) Remove(id int) error {
|
||||||
mus.Lock()
|
s.Lock()
|
||||||
_, ok := mus.items[id]
|
_, ok := s.items[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
mus.Unlock()
|
s.Unlock()
|
||||||
return ErrNoRows
|
return ErrNoRows
|
||||||
}
|
}
|
||||||
delete(mus.items, id)
|
delete(s.items, id)
|
||||||
mus.Unlock()
|
s.Unlock()
|
||||||
atomic.AddInt64(&mus.length, -1)
|
atomic.AddInt64(&s.length, -1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveUnsafe is the unsafe version of Remove. THIS METHOD IS NOT THREAD-SAFE.
|
// RemoveUnsafe is the unsafe version of Remove. THIS METHOD IS NOT THREAD-SAFE.
|
||||||
func (mus *MemoryPollCache) RemoveUnsafe(id int) error {
|
func (s *MemoryPollCache) RemoveUnsafe(id int) error {
|
||||||
_, ok := mus.items[id]
|
_, ok := s.items[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrNoRows
|
return ErrNoRows
|
||||||
}
|
}
|
||||||
delete(mus.items, id)
|
delete(s.items, id)
|
||||||
atomic.AddInt64(&mus.length, -1)
|
atomic.AddInt64(&s.length, -1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush removes all the polls from the cache, useful for tests.
|
// Flush removes all the polls from the cache, useful for tests.
|
||||||
func (mus *MemoryPollCache) Flush() {
|
func (s *MemoryPollCache) Flush() {
|
||||||
mus.Lock()
|
s.Lock()
|
||||||
mus.items = make(map[int]*Poll)
|
s.items = make(map[int]*Poll)
|
||||||
mus.length = 0
|
s.length = 0
|
||||||
mus.Unlock()
|
s.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! Is this concurrent?
|
// ! Is this concurrent?
|
||||||
// Length returns the number of polls in the memory cache
|
// Length returns the number of polls in the memory cache
|
||||||
func (mus *MemoryPollCache) Length() int {
|
func (s *MemoryPollCache) Length() int {
|
||||||
return int(mus.length)
|
return int(s.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCapacity sets the maximum number of polls which this cache can hold
|
// SetCapacity sets the maximum number of polls which this cache can hold
|
||||||
func (mus *MemoryPollCache) SetCapacity(capacity int) {
|
func (s *MemoryPollCache) SetCapacity(capacity int) {
|
||||||
// Ints are moved in a single instruction, so this should be thread-safe
|
// Ints are moved in a single instruction, so this should be thread-safe
|
||||||
mus.capacity = capacity
|
s.capacity = capacity
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCapacity returns the maximum number of polls this cache can hold
|
// GetCapacity returns the maximum number of polls this cache can hold
|
||||||
func (mus *MemoryPollCache) GetCapacity() int {
|
func (s *MemoryPollCache) GetCapacity() int {
|
||||||
return mus.capacity
|
return s.capacity
|
||||||
}
|
}
|
||||||
|
|
||||||
// NullPollCache is a poll cache to be used when you don't want a cache and just want queries to passthrough to the database
|
// NullPollCache is a poll cache to be used when you don't want a cache and just want queries to passthrough to the database
|
||||||
|
@ -171,37 +171,37 @@ func NewNullPollCache() *NullPollCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint
|
// nolint
|
||||||
func (mus *NullPollCache) Get(id int) (*Poll, error) {
|
func (s *NullPollCache) Get(id int) (*Poll, error) {
|
||||||
return nil, ErrNoRows
|
return nil, ErrNoRows
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) BulkGet(ids []int) (list []*Poll) {
|
func (s *NullPollCache) BulkGet(ids []int) (list []*Poll) {
|
||||||
return make([]*Poll, len(ids))
|
return make([]*Poll, len(ids))
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) GetUnsafe(id int) (*Poll, error) {
|
func (s *NullPollCache) GetUnsafe(id int) (*Poll, error) {
|
||||||
return nil, ErrNoRows
|
return nil, ErrNoRows
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) Set(_ *Poll) error {
|
func (s *NullPollCache) Set(_ *Poll) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) Add(_ *Poll) error {
|
func (s *NullPollCache) Add(_ *Poll) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) AddUnsafe(_ *Poll) error {
|
func (s *NullPollCache) AddUnsafe(_ *Poll) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) Remove(id int) error {
|
func (s *NullPollCache) Remove(id int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) RemoveUnsafe(id int) error {
|
func (s *NullPollCache) RemoveUnsafe(id int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) Flush() {
|
func (s *NullPollCache) Flush() {
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) Length() int {
|
func (s *NullPollCache) Length() int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) SetCapacity(_ int) {
|
func (s *NullPollCache) SetCapacity(_ int) {
|
||||||
}
|
}
|
||||||
func (mus *NullPollCache) GetCapacity() int {
|
func (s *NullPollCache) GetCapacity() int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,10 +40,10 @@ func NewMemoryReplyCache(capacity int) *MemoryReplyCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get fetches a reply by ID. Returns ErrNoRows if not present.
|
// Get fetches a reply by ID. Returns ErrNoRows if not present.
|
||||||
func (mts *MemoryReplyCache) Get(id int) (*Reply, error) {
|
func (s *MemoryReplyCache) Get(id int) (*Reply, error) {
|
||||||
mts.RLock()
|
s.RLock()
|
||||||
item, ok := mts.items[id]
|
item, ok := s.items[id]
|
||||||
mts.RUnlock()
|
s.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ func (mts *MemoryReplyCache) Get(id int) (*Reply, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUnsafe fetches a reply by ID. Returns ErrNoRows if not present. THIS METHOD IS NOT THREAD-SAFE.
|
// GetUnsafe fetches a reply by ID. Returns ErrNoRows if not present. THIS METHOD IS NOT THREAD-SAFE.
|
||||||
func (mts *MemoryReplyCache) GetUnsafe(id int) (*Reply, error) {
|
func (s *MemoryReplyCache) GetUnsafe(id int) (*Reply, error) {
|
||||||
item, ok := mts.items[id]
|
item, ok := s.items[id]
|
||||||
if ok {
|
if ok {
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
|
@ -60,69 +60,69 @@ func (mts *MemoryReplyCache) GetUnsafe(id int) (*Reply, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BulkGet fetches multiple replies by their IDs. Indices without replies will be set to nil, so make sure you check for those, we might want to change this behaviour to make it less confusing.
|
// BulkGet fetches multiple replies by their IDs. Indices without replies will be set to nil, so make sure you check for those, we might want to change this behaviour to make it less confusing.
|
||||||
func (c *MemoryReplyCache) BulkGet(ids []int) (list []*Reply) {
|
func (s *MemoryReplyCache) BulkGet(ids []int) (list []*Reply) {
|
||||||
list = make([]*Reply, len(ids))
|
list = make([]*Reply, len(ids))
|
||||||
c.RLock()
|
s.RLock()
|
||||||
for i, id := range ids {
|
for i, id := range ids {
|
||||||
list[i] = c.items[id]
|
list[i] = s.items[id]
|
||||||
}
|
}
|
||||||
c.RUnlock()
|
s.RUnlock()
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set overwrites the value of a reply in the cache, whether it's present or not. May return a capacity overflow error.
|
// Set overwrites the value of a reply in the cache, whether it's present or not. May return a capacity overflow error.
|
||||||
func (mts *MemoryReplyCache) Set(item *Reply) error {
|
func (s *MemoryReplyCache) Set(item *Reply) error {
|
||||||
mts.Lock()
|
s.Lock()
|
||||||
_, ok := mts.items[item.ID]
|
_, ok := s.items[item.ID]
|
||||||
if ok {
|
if ok {
|
||||||
mts.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
} else if int(mts.length) >= mts.capacity {
|
} else if int(s.length) >= s.capacity {
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
return ErrStoreCapacityOverflow
|
return ErrStoreCapacityOverflow
|
||||||
} else {
|
} else {
|
||||||
mts.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
atomic.AddInt64(&mts.length, 1)
|
atomic.AddInt64(&s.length, 1)
|
||||||
}
|
}
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds a reply to the cache, similar to Set, but it's only intended for new items. This method might be deprecated in the near future, use Set. May return a capacity overflow error.
|
// Add adds a reply to the cache, similar to Set, but it's only intended for new items. This method might be deprecated in the near future, use Set. May return a capacity overflow error.
|
||||||
// ? Is this redundant if we have Set? Are the efficiency wins worth this? Is this even used?
|
// ? Is this redundant if we have Set? Are the efficiency wins worth this? Is this even used?
|
||||||
func (mts *MemoryReplyCache) Add(item *Reply) error {
|
func (s *MemoryReplyCache) Add(item *Reply) error {
|
||||||
log.Print("MemoryReplyCache.Add")
|
log.Print("MemoryReplyCache.Add")
|
||||||
mts.Lock()
|
s.Lock()
|
||||||
if int(mts.length) >= mts.capacity {
|
if int(s.length) >= s.capacity {
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
return ErrStoreCapacityOverflow
|
return ErrStoreCapacityOverflow
|
||||||
}
|
}
|
||||||
mts.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
atomic.AddInt64(&mts.length, 1)
|
atomic.AddInt64(&s.length, 1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUnsafe is the unsafe version of Add. May return a capacity overflow error. THIS METHOD IS NOT THREAD-SAFE.
|
// AddUnsafe is the unsafe version of Add. May return a capacity overflow error. THIS METHOD IS NOT THREAD-SAFE.
|
||||||
func (mts *MemoryReplyCache) AddUnsafe(item *Reply) error {
|
func (s *MemoryReplyCache) AddUnsafe(item *Reply) error {
|
||||||
if int(mts.length) >= mts.capacity {
|
if int(s.length) >= s.capacity {
|
||||||
return ErrStoreCapacityOverflow
|
return ErrStoreCapacityOverflow
|
||||||
}
|
}
|
||||||
mts.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
mts.length = int64(len(mts.items))
|
s.length = int64(len(s.items))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove removes a reply from the cache by ID, if they exist. Returns ErrNoRows if no items exist.
|
// Remove removes a reply from the cache by ID, if they exist. Returns ErrNoRows if no items exist.
|
||||||
func (mts *MemoryReplyCache) Remove(id int) error {
|
func (s *MemoryReplyCache) Remove(id int) error {
|
||||||
mts.Lock()
|
s.Lock()
|
||||||
_, ok := mts.items[id]
|
_, ok := s.items[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
return ErrNoRows
|
return ErrNoRows
|
||||||
}
|
}
|
||||||
delete(mts.items, id)
|
delete(s.items, id)
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
atomic.AddInt64(&mts.length, -1)
|
atomic.AddInt64(&s.length, -1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,10 @@ func NewMemoryTopicCache(capacity int) *MemoryTopicCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get fetches a topic by ID. Returns ErrNoRows if not present.
|
// Get fetches a topic by ID. Returns ErrNoRows if not present.
|
||||||
func (mts *MemoryTopicCache) Get(id int) (*Topic, error) {
|
func (s *MemoryTopicCache) Get(id int) (*Topic, error) {
|
||||||
mts.RLock()
|
s.RLock()
|
||||||
item, ok := mts.items[id]
|
item, ok := s.items[id]
|
||||||
mts.RUnlock()
|
s.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,8 @@ func (mts *MemoryTopicCache) Get(id int) (*Topic, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUnsafe fetches a topic by ID. Returns ErrNoRows if not present. THIS METHOD IS NOT THREAD-SAFE.
|
// GetUnsafe fetches a topic by ID. Returns ErrNoRows if not present. THIS METHOD IS NOT THREAD-SAFE.
|
||||||
func (mts *MemoryTopicCache) GetUnsafe(id int) (*Topic, error) {
|
func (s *MemoryTopicCache) GetUnsafe(id int) (*Topic, error) {
|
||||||
item, ok := mts.items[id]
|
item, ok := s.items[id]
|
||||||
if ok {
|
if ok {
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
|
@ -59,68 +59,68 @@ func (mts *MemoryTopicCache) GetUnsafe(id int) (*Topic, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BulkGet fetches multiple topics by their IDs. Indices without topics will be set to nil, so make sure you check for those, we might want to change this behaviour to make it less confusing.
|
// BulkGet fetches multiple topics by their IDs. Indices without topics will be set to nil, so make sure you check for those, we might want to change this behaviour to make it less confusing.
|
||||||
func (c *MemoryTopicCache) BulkGet(ids []int) (list []*Topic) {
|
func (s *MemoryTopicCache) BulkGet(ids []int) (list []*Topic) {
|
||||||
list = make([]*Topic, len(ids))
|
list = make([]*Topic, len(ids))
|
||||||
c.RLock()
|
s.RLock()
|
||||||
for i, id := range ids {
|
for i, id := range ids {
|
||||||
list[i] = c.items[id]
|
list[i] = s.items[id]
|
||||||
}
|
}
|
||||||
c.RUnlock()
|
s.RUnlock()
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set overwrites the value of a topic in the cache, whether it's present or not. May return a capacity overflow error.
|
// Set overwrites the value of a topic in the cache, whether it's present or not. May return a capacity overflow error.
|
||||||
func (mts *MemoryTopicCache) Set(item *Topic) error {
|
func (s *MemoryTopicCache) Set(item *Topic) error {
|
||||||
mts.Lock()
|
s.Lock()
|
||||||
_, ok := mts.items[item.ID]
|
_, ok := s.items[item.ID]
|
||||||
if ok {
|
if ok {
|
||||||
mts.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
} else if int(mts.length) >= mts.capacity {
|
} else if int(s.length) >= s.capacity {
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
return ErrStoreCapacityOverflow
|
return ErrStoreCapacityOverflow
|
||||||
} else {
|
} else {
|
||||||
mts.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
atomic.AddInt64(&mts.length, 1)
|
atomic.AddInt64(&s.length, 1)
|
||||||
}
|
}
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds a topic to the cache, similar to Set, but it's only intended for new items. This method might be deprecated in the near future, use Set. May return a capacity overflow error.
|
// Add adds a topic to the cache, similar to Set, but it's only intended for new items. This method might be deprecated in the near future, use Set. May return a capacity overflow error.
|
||||||
// ? Is this redundant if we have Set? Are the efficiency wins worth this? Is this even used?
|
// ? Is this redundant if we have Set? Are the efficiency wins worth this? Is this even used?
|
||||||
func (mts *MemoryTopicCache) Add(item *Topic) error {
|
func (s *MemoryTopicCache) Add(item *Topic) error {
|
||||||
mts.Lock()
|
s.Lock()
|
||||||
if int(mts.length) >= mts.capacity {
|
if int(s.length) >= s.capacity {
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
return ErrStoreCapacityOverflow
|
return ErrStoreCapacityOverflow
|
||||||
}
|
}
|
||||||
mts.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
atomic.AddInt64(&mts.length, 1)
|
atomic.AddInt64(&s.length, 1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUnsafe is the unsafe version of Add. May return a capacity overflow error. THIS METHOD IS NOT THREAD-SAFE.
|
// AddUnsafe is the unsafe version of Add. May return a capacity overflow error. THIS METHOD IS NOT THREAD-SAFE.
|
||||||
func (mts *MemoryTopicCache) AddUnsafe(item *Topic) error {
|
func (s *MemoryTopicCache) AddUnsafe(item *Topic) error {
|
||||||
if int(mts.length) >= mts.capacity {
|
if int(s.length) >= s.capacity {
|
||||||
return ErrStoreCapacityOverflow
|
return ErrStoreCapacityOverflow
|
||||||
}
|
}
|
||||||
mts.items[item.ID] = item
|
s.items[item.ID] = item
|
||||||
mts.length = int64(len(mts.items))
|
s.length = int64(len(s.items))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove removes a topic from the cache by ID, if they exist. Returns ErrNoRows if no items exist.
|
// Remove removes a topic from the cache by ID, if they exist. Returns ErrNoRows if no items exist.
|
||||||
func (mts *MemoryTopicCache) Remove(id int) error {
|
func (s *MemoryTopicCache) Remove(id int) error {
|
||||||
mts.Lock()
|
s.Lock()
|
||||||
_, ok := mts.items[id]
|
_, ok := s.items[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
return ErrNoRows
|
return ErrNoRows
|
||||||
}
|
}
|
||||||
delete(mts.items, id)
|
delete(s.items, id)
|
||||||
mts.Unlock()
|
s.Unlock()
|
||||||
atomic.AddInt64(&mts.length, -1)
|
atomic.AddInt64(&s.length, -1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="colstack_item the_form">
|
<div class="colstack_item the_form">
|
||||||
<form action="/user/convos/create/submit/?session={{.CurrentUser.Session}}" method="post">
|
<form action="/user/convos/create/submit/?s={{.CurrentUser.Session}}" method="post">
|
||||||
<div class="formrow real_first_child">
|
<div class="formrow real_first_child">
|
||||||
<div class="formitem formlabel"><a>Recipient/s</a></div>
|
<div class="formitem formlabel"><a>Recipient/s</a></div>
|
||||||
<div class="formitem"><input name="recp" type="text"{{if .RecpName}} value="{{.RecpName}}"{{end}} /></div>
|
<div class="formitem"><input name="recp" type="text"{{if .RecpName}} value="{{.RecpName}}"{{end}} /></div>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<div class="rowitem"><h1>{{lang "create_topic_head"}}</h1></div>
|
<div class="rowitem"><h1>{{lang "create_topic_head"}}</h1></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="rowblock the_form">
|
<div class="rowblock the_form">
|
||||||
<form id="quick_post_form" enctype="multipart/form-data" action="/topic/create/submit/?session={{.CurrentUser.Session}}" method="post"></form>
|
<form id="quick_post_form" enctype="multipart/form-data" action="/topic/create/submit/?s={{.CurrentUser.Session}}" method="post"></form>
|
||||||
<div class="formrow real_first_child">
|
<div class="formrow real_first_child">
|
||||||
<div class="formitem formlabel"><a>{{lang "create_topic_board"}}</a></div>
|
<div class="formitem formlabel"><a>{{lang "create_topic_board"}}</a></div>
|
||||||
<div class="formitem"><select form="quick_post_form" id="topic_board_input" name="topic-board">
|
<div class="formitem"><select form="quick_post_form" id="topic_board_input" name="topic-board">
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
{{if .CurrentUser.Perms.CreateTopic}}
|
{{if .CurrentUser.Perms.CreateTopic}}
|
||||||
<div id="forum_topic_create_form" class="rowblock topic_create_form quick_create_form" style="display:none;" aria-label="{{lang "quick_topic.aria"}}">
|
<div id="forum_topic_create_form" class="rowblock topic_create_form quick_create_form" style="display:none;" aria-label="{{lang "quick_topic.aria"}}">
|
||||||
<form id="quick_post_form" enctype="multipart/form-data" action="/topic/create/submit/?session={{.CurrentUser.Session}}" method="post"></form>
|
<form id="quick_post_form" enctype="multipart/form-data" action="/topic/create/submit/?s={{.CurrentUser.Session}}" method="post"></form>
|
||||||
<img class="little_row_avatar" src="{{.CurrentUser.MicroAvatar}}" height=64 alt="{{lang "quick_topic.avatar_alt"}}" title="{{lang "quick_topic.avatar_tooltip"}}" />
|
<img class="little_row_avatar" src="{{.CurrentUser.MicroAvatar}}" height=64 alt="{{lang "quick_topic.avatar_alt"}}" title="{{lang "quick_topic.avatar_tooltip"}}" />
|
||||||
<input form="quick_post_form" id="topic_board_input" name="topic-board" value="{{.Forum.ID}}" type="hidden">
|
<input form="quick_post_form" id="topic_board_input" name="topic-board" value="{{.Forum.ID}}" type="hidden">
|
||||||
<div class="main_form">
|
<div class="main_form">
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
{{template "topics_mod_floater.html"}}
|
{{template "topics_mod_floater.html"}}
|
||||||
|
|
||||||
{{if .CurrentUser.Perms.CreateTopic}}
|
{{if .CurrentUser.Perms.CreateTopic}}
|
||||||
<div id="forum_topic_create_form" class="rowblock topic_create_form quick_create_form" style="display: none;" aria-label="{{lang "quick_topic.aria"}}">
|
<div id="forum_topic_create_form" class="rowblock topic_create_form quick_create_form" style="display:none;" aria-label="{{lang "quick_topic.aria"}}">
|
||||||
<form id="quick_post_form" enctype="multipart/form-data" action="/topic/create/submit/?session={{.CurrentUser.Session}}" method="post"></form>
|
<form id="quick_post_form" enctype="multipart/form-data" action="/topic/create/submit/?s={{.CurrentUser.Session}}" method="post"></form>
|
||||||
<img class="little_row_avatar" src="{{.CurrentUser.MicroAvatar}}" height=64 alt="{{lang "quick_topic.avatar_alt"}}" title="{{lang "quick_topic.avatar_tooltip"}}" />
|
<img class="little_row_avatar" src="{{.CurrentUser.MicroAvatar}}" height=64 alt="{{lang "quick_topic.avatar_alt"}}" title="{{lang "quick_topic.avatar_tooltip"}}" />
|
||||||
<input form="quick_post_form" id="topic_board_input" name="topic-board" value="{{.Forum.ID}}" type="hidden">
|
<input form="quick_post_form" id="topic_board_input" name="topic-board" value="{{.Forum.ID}}" type="hidden">
|
||||||
<div class="main_form">
|
<div class="main_form">
|
||||||
|
|
Loading…
Reference in New Issue