Commit 5999bcfb authored by Sietse Ringers's avatar Sietse Ringers
Browse files

refactor: rename some log functions and vars

parent ad669a7c
...@@ -224,18 +224,18 @@ func (s *storage) LoadKeyshareServers() (ksses map[irma.SchemeManagerIdentifier] ...@@ -224,18 +224,18 @@ func (s *storage) LoadKeyshareServers() (ksses map[irma.SchemeManagerIdentifier]
return ksses, nil return ksses, nil
} }
// Returns all logs stored before log with ID 'startBeforeIndex' sorted from new to old with // Returns all logs stored before log with ID 'index' sorted from new to old with
// a maximum result length of 'max'. // a maximum result length of 'max'.
func (s *storage) LoadLogsBefore(startBeforeIndex uint64, max int) ([]*LogEntry, error) { func (s *storage) LoadLogsBefore(index uint64, max int) ([]*LogEntry, error) {
return s.loadLogsFromBbolt(max, func(c *bbolt.Cursor) (key, value []byte) { return s.loadLogs(max, func(c *bbolt.Cursor) (key, value []byte) {
c.Seek(s.logEntryKeyToBytes(startBeforeIndex)) c.Seek(s.logEntryKeyToBytes(index))
return c.Prev() return c.Prev()
}) })
} }
// Returns the latest logs stored sorted from new to old with a maximum result length of 'max' // Returns the latest logs stored sorted from new to old with a maximum result length of 'max'
func (s *storage) LoadNewestLogs(max int) ([]*LogEntry, error) { func (s *storage) LoadNewestLogs(max int) ([]*LogEntry, error) {
return s.loadLogsFromBbolt(max, func(c *bbolt.Cursor) (key, value []byte) { return s.loadLogs(max, func(c *bbolt.Cursor) (key, value []byte) {
return c.Last() return c.Last()
}) })
} }
...@@ -243,8 +243,8 @@ func (s *storage) LoadNewestLogs(max int) ([]*LogEntry, error) { ...@@ -243,8 +243,8 @@ func (s *storage) LoadNewestLogs(max int) ([]*LogEntry, error) {
// Returns the logs stored sorted from new to old with a maximum result length of 'max' where the starting position // Returns the logs stored sorted from new to old with a maximum result length of 'max' where the starting position
// of the bbolt cursor can be manipulated by the anonymous function 'startAt'. 'startAt' should return // of the bbolt cursor can be manipulated by the anonymous function 'startAt'. 'startAt' should return
// the key and the value of the first element from the bbolt database that should be loaded. // the key and the value of the first element from the bbolt database that should be loaded.
func (s *storage) loadLogsFromBbolt(max int, startAt func(*bbolt.Cursor) (key, value []byte)) ([]*LogEntry, error) { func (s *storage) loadLogs(max int, startAt func(*bbolt.Cursor) (key, value []byte)) ([]*LogEntry, error) {
var logs []*LogEntry logs := make([]*LogEntry, 0, max)
return logs, s.db.View(func(tx *bbolt.Tx) error { return logs, s.db.View(func(tx *bbolt.Tx) error {
bucket := tx.Bucket([]byte(logsBucket)) bucket := tx.Bucket([]byte(logsBucket))
if bucket == nil { if bucket == nil {
......
...@@ -2,7 +2,6 @@ package irmaclient ...@@ -2,7 +2,6 @@ package irmaclient
import ( import (
"encoding/json" "encoding/json"
"fmt"
"time" "time"
"github.com/privacybydesign/irmago" "github.com/privacybydesign/irmago"
...@@ -47,16 +46,9 @@ var clientUpdates = []func(client *Client) error{ ...@@ -47,16 +46,9 @@ var clientUpdates = []func(client *Client) error{
func(client *Client) error { func(client *Client) error {
var logs []*LogEntry var logs []*LogEntry
var err error var err error
start := time.Now()
fmt.Println(start.UnixNano(), "started")
if err = client.storage.load(&logs, logsFile); err != nil { if err = client.storage.load(&logs, logsFile); err != nil {
return err return err
} }
loaded := time.Now()
fmt.Println(loaded.Sub(start), "loaded")
// Open one bolt transaction to process all our log entries in // Open one bolt transaction to process all our log entries in
err = client.storage.db.Update(func(tx *bbolt.Tx) error { err = client.storage.db.Update(func(tx *bbolt.Tx) error {
for _, log := range logs { for _, log := range logs {
...@@ -77,10 +69,6 @@ var clientUpdates = []func(client *Client) error{ ...@@ -77,10 +69,6 @@ var clientUpdates = []func(client *Client) error{
} }
return nil return nil
}) })
done := time.Now()
fmt.Println(done.Sub(loaded), "done converting", len(logs), "logs")
return err return err
}, },
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment