|
|
|
@ -4,9 +4,7 @@ import ( |
|
|
|
|
"fmt" |
|
|
|
|
"html" |
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
"git.eeqj.de/sneak/feta/toot" |
|
|
|
|
|
|
|
|
|
"github.com/google/uuid" |
|
|
|
|
hstg "github.com/grokify/html-strip-tags-go" |
|
|
|
|
_ "github.com/jinzhu/gorm/dialects/sqlite" |
|
|
|
@ -15,24 +13,15 @@ import ( |
|
|
|
|
func (m *Manager) TootInsertHashCacheSize() uint { |
|
|
|
|
m.cachelock.Lock() |
|
|
|
|
defer m.cachelock.Unlock() |
|
|
|
|
return uint(len(*m.recentlyInsertedTootHashCache)) |
|
|
|
|
return uint(m.recentlyInsertedTootHashCache.Len()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Manager) TootExists(t *toot.Toot) bool { |
|
|
|
|
var try StoredToot |
|
|
|
|
|
|
|
|
|
// first, nuke cache if it gets too big to prevent
|
|
|
|
|
// unlimited memory usage
|
|
|
|
|
m.cachelock.Lock() |
|
|
|
|
if len(*m.recentlyInsertedTootHashCache) > 1000000 { |
|
|
|
|
emptycache := make(map[string]bool) |
|
|
|
|
m.recentlyInsertedTootHashCache = &emptycache |
|
|
|
|
} |
|
|
|
|
m.cachelock.Unlock() |
|
|
|
|
|
|
|
|
|
// check cache
|
|
|
|
|
m.cachelock.Lock() |
|
|
|
|
// check map
|
|
|
|
|
if _, ok := (*m.recentlyInsertedTootHashCache)[t.GetHash()]; ok { |
|
|
|
|
if _, ok := m.recentlyInsertedTootHashCache.Get(t.GetHash()); ok { |
|
|
|
|
m.cachelock.Unlock() |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
@ -67,7 +56,7 @@ func (m *Manager) StoreToot(t *toot.Toot) error { |
|
|
|
|
|
|
|
|
|
// put it in the cache to avoid relying on db for dedupe:
|
|
|
|
|
m.cachelock.Lock() |
|
|
|
|
(*m.recentlyInsertedTootHashCache)[nt.Hash] = true |
|
|
|
|
m.recentlyInsertedTootHashCache.Add(nt.Hash, true) |
|
|
|
|
m.cachelock.Unlock() |
|
|
|
|
|
|
|
|
|
//panic(fmt.Sprintf("%+v", t))
|
|
|
|
|