mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-04 01:58:31 +00:00
try gob.registername??
This commit is contained in:
parent
987286a607
commit
daeb9d1a06
2 changed files with 12 additions and 5 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"os"
|
"os"
|
||||||
|
"github.com/satori/go.uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
var SERVERS = []string{
|
var SERVERS = []string{
|
||||||
|
@ -37,6 +38,7 @@ func main() {
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
gob.RegisterName("hyperloglog", hyperloglog.HyperLogLogPlus{})
|
||||||
|
|
||||||
filename := flag.Arg(1)
|
filename := flag.Arg(1)
|
||||||
hll, err := DownloadAll(filename)
|
hll, err := DownloadAll(filename)
|
||||||
|
@ -70,9 +72,13 @@ func DownloadHLL(url string) (*hyperloglog.HyperLogLogPlus, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
dec := gob.NewDecoder(resp.Body)
|
dec := gob.NewDecoder(resp.Body)
|
||||||
dec.Decode(result)
|
err = dec.Decode(result)
|
||||||
resp.Body.Close()
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Println(url, result.Count())
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// uuidHash implements a hash for uuid.UUID by XORing the random bits.
|
// uuidHash implements a hash for uuid.UUID by XORing the random bits.
|
||||||
type uuidHash uuid.UUID
|
type UuidHash uuid.UUID
|
||||||
|
|
||||||
func (u uuidHash) Sum64() uint64 {
|
func (u UuidHash) Sum64() uint64 {
|
||||||
var valLow, valHigh uint64
|
var valLow, valHigh uint64
|
||||||
valLow = binary.LittleEndian.Uint64(u[0:8])
|
valLow = binary.LittleEndian.Uint64(u[0:8])
|
||||||
valHigh = binary.LittleEndian.Uint64(u[8:16])
|
valHigh = binary.LittleEndian.Uint64(u[8:16])
|
||||||
|
@ -173,6 +173,7 @@ func HTTPWriteHLL(w http.ResponseWriter, r *http.Request) {
|
||||||
// loadUniqueUsers loads the previous HLLs into memory.
|
// loadUniqueUsers loads the previous HLLs into memory.
|
||||||
// is_init_func
|
// is_init_func
|
||||||
func loadUniqueUsers() {
|
func loadUniqueUsers() {
|
||||||
|
gob.RegisterName("hyperloglog", hyperloglog.HyperLogLogPlus{})
|
||||||
err := os.MkdirAll(uniqCountDir, 0755)
|
err := os.MkdirAll(uniqCountDir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln("could not make unique users data dir:", err)
|
log.Panicln("could not make unique users data dir:", err)
|
||||||
|
@ -217,7 +218,7 @@ func processNewUsers() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case u := <-uniqueUserChannel:
|
case u := <-uniqueUserChannel:
|
||||||
hashed := uuidHash(u)
|
hashed := UuidHash(u)
|
||||||
for _, period := range periods {
|
for _, period := range periods {
|
||||||
uniqueCounters[period].Counter.Add(hashed)
|
uniqueCounters[period].Counter.Add(hashed)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue