Skip to content

Commit

Permalink
Add ClearIPs() to TopicStore.
Browse files Browse the repository at this point in the history
Add LockMany() to TopicStore.
Add RemoveMany() to TopicCache.
Add ClearIPs() to PollStore.
Add Purge() to RegLogStore.
Add DeleteOlderThanDays() to RegLogStore.
Add Purge() to LoginLogStore.
Add DeleteOlderThanDays() to LoginLogStore.
Add SetInt() to MetaStore.
Add SetInt64() to MetaStore.

Use Createf() in RegLogItem.Create()
Use Count() in SQLRegLogStore.Count()
Use Count() in SQLLoginLogStore.Count()
Use Countf() in SQLLoginLogStore.CountUser()

Add trailing triple dot parser test case.
Removed a block of commented code in gen router.
Reduce boilerplate.
  • Loading branch information
Azareal committed Apr 27, 2021
1 parent 1b7d6ac commit 6870d24
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 176 deletions.
16 changes: 8 additions & 8 deletions common/counters/forums.go
Expand Up @@ -48,18 +48,18 @@ func (co *DefaultForumViewCounter) Tick() error {
l.Lock()
delete(m, fid)
l.Unlock()
err := co.insertChunk(count, fid)
if err != nil {
return errors.Wrap(errors.WithStack(err),"forum counter")
e := co.insertChunk(count, fid)
if e != nil {
return errors.Wrap(errors.WithStack(e),"forum counter")
}
l.RLock()
}
l.RUnlock()
return nil
}
err := cLoop(&co.oddLock,co.oddMap)
if err != nil {
return err
e := cLoop(&co.oddLock,co.oddMap)
if e != nil {
return e
}
return cLoop(&co.evenLock,co.evenMap)
}
Expand All @@ -69,8 +69,8 @@ func (co *DefaultForumViewCounter) insertChunk(count, forum int) error {
return nil
}
c.DebugLogf("Inserting a vchunk with a count of %d for forum %d", count, forum)
_, err := co.insert.Exec(count, forum)
return err
_, e := co.insert.Exec(count, forum)
return e
}

func (co *DefaultForumViewCounter) Bump(fid int) {
Expand Down
10 changes: 5 additions & 5 deletions common/counters/langs.go
Expand Up @@ -127,9 +127,9 @@ func NewDefaultLangViewCounter(acc *qgen.Accumulator) (*DefaultLangViewCounter,
func (co *DefaultLangViewCounter) Tick() error {
for id := 0; id < len(co.buckets); id++ {
count := atomic.SwapInt64(&co.buckets[id], 0)
err := co.insertChunk(count, id) // TODO: Bulk insert for speed?
if err != nil {
return errors.Wrap(errors.WithStack(err), "langview counter")
e := co.insertChunk(count, id) // TODO: Bulk insert for speed?
if e != nil {
return errors.Wrap(errors.WithStack(e), "langview counter")
}
}
return nil
Expand All @@ -144,8 +144,8 @@ func (co *DefaultLangViewCounter) insertChunk(count int64, id int) error {
langCode = "none"
}
c.DebugLogf("Inserting a vchunk with a count of %d for lang %s (%d)", count, langCode, id)
_, err := co.insert.Exec(count, langCode)
return err
_, e := co.insert.Exec(count, langCode)
return e
}

func (co *DefaultLangViewCounter) Bump(langCode string) (validCode bool) {
Expand Down
8 changes: 4 additions & 4 deletions common/counters/memory.go
Expand Up @@ -54,7 +54,7 @@ func NewMemoryCounter(acc *qgen.Accumulator) (*DefaultMemoryCounter, error) {
return co, acc.FirstError()
}

func (co *DefaultMemoryCounter) Tick() (err error) {
func (co *DefaultMemoryCounter) Tick() (e error) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
var rTotMem, rTotCount, rStackMem, rStackCount, rHeapMem, rHeapCount uint64
Expand Down Expand Up @@ -83,9 +83,9 @@ func (co *DefaultMemoryCounter) Tick() (err error) {
avgHeap = (rHeapMem + m.HeapAlloc) / (rHeapCount + 1)

c.DebugLogf("Inserting a memchunk with a value of %d - %d - %d", avgMem, avgStack, avgHeap)
_, err = co.insert.Exec(avgMem, avgStack, avgHeap)
if err != nil {
return errors.Wrap(errors.WithStack(err), "mem counter")
_, e = co.insert.Exec(avgMem, avgStack, avgHeap)
if e != nil {
return errors.Wrap(errors.WithStack(e), "mem counter")
}
return nil
}
12 changes: 6 additions & 6 deletions common/counters/topics.go
Expand Up @@ -30,7 +30,7 @@ func NewTopicCounter() (*DefaultTopicCounter, error) {
return co, acc.FirstError()
}

func (co *DefaultTopicCounter) Tick() (err error) {
func (co *DefaultTopicCounter) Tick() (e error) {
oldBucket := co.currentBucket
var nextBucket int64 // 0
if co.currentBucket == 0 {
Expand All @@ -42,9 +42,9 @@ func (co *DefaultTopicCounter) Tick() (err error) {

previousViewChunk := co.buckets[oldBucket]
atomic.AddInt64(&co.buckets[oldBucket], -previousViewChunk)
err = co.insertChunk(previousViewChunk)
if err != nil {
return errors.Wrap(errors.WithStack(err), "topics counter")
e = co.insertChunk(previousViewChunk)
if e != nil {
return errors.Wrap(errors.WithStack(e), "topics counter")
}
return nil
}
Expand All @@ -58,6 +58,6 @@ func (co *DefaultTopicCounter) insertChunk(count int64) error {
return nil
}
c.DebugLogf("Inserting a topicchunk with a count of %d", count)
_, err := co.insert.Exec(count)
return err
_, e := co.insert.Exec(count)
return e
}
43 changes: 29 additions & 14 deletions common/meta/meta_store.go
Expand Up @@ -10,6 +10,8 @@ import (
type MetaStore interface {
Get(name string) (val string, err error)
Set(name, val string) error
SetInt(name string, val int) error
SetInt64(name string, val int64) error
}

type DefaultMetaStore struct {
Expand All @@ -19,28 +21,41 @@ type DefaultMetaStore struct {
}

func NewDefaultMetaStore(acc *qgen.Accumulator) (*DefaultMetaStore, error) {
t := "meta"
m := &DefaultMetaStore{
get: acc.Select("meta").Columns("value").Where("name = ?").Prepare(),
set: acc.Update("meta").Set("value = ?").Where("name = ?").Prepare(),
add: acc.Insert("meta").Columns("name,value").Fields("?,''").Prepare(),
get: acc.Select(t).Columns("value").Where("name=?").Prepare(),
set: acc.Update(t).Set("value=?").Where("name=?").Prepare(),
add: acc.Insert(t).Columns("name,value").Fields("?,''").Prepare(),
}
return m, acc.FirstError()
}

func (s *DefaultMetaStore) Get(name string) (val string, err error) {
err = s.get.QueryRow(name).Scan(&val)
return val, err
func (s *DefaultMetaStore) Get(name string) (val string, e error) {
e = s.get.QueryRow(name).Scan(&val)
return val, e
}

// TODO: Use timestamped rows as a more robust method of ensuring data integrity
func (s *DefaultMetaStore) Set(name, val string) error {
_, err := s.Get(name)
if err == sql.ErrNoRows {
_, err := s.add.Exec(name)
if err != nil {
return err
func (s *DefaultMetaStore) setVal(name string, val interface{}) error {
_, e := s.Get(name)
if e == sql.ErrNoRows {
_, e := s.add.Exec(name)
if e != nil {
return e
}
}
_, err = s.set.Exec(val, name)
return err
_, e = s.set.Exec(val, name)
return e
}

func (s *DefaultMetaStore) Set(name, val string) error {
return s.setVal(name, val)
}

func (s *DefaultMetaStore) SetInt(name string, val int) error {
return s.setVal(name, val)
}

func (s *DefaultMetaStore) SetInt64(name string, val int64) error {
return s.setVal(name, val)
}

0 comments on commit 6870d24

Please sign in to comment.