Cache results
This commit is contained in:
parent
bd9a72920f
commit
5b795b1e93
6
model.go
6
model.go
@ -17,6 +17,7 @@ type GimeDB struct {
|
|||||||
filename, arch string
|
filename, arch string
|
||||||
|
|
||||||
AllTypes []int
|
AllTypes []int
|
||||||
|
TypeCollections map[int]*TimeEntryCollection
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -53,6 +54,7 @@ func LoadDatabase(path, name, archName string) (*GimeDB, error) {
|
|||||||
filename: name,
|
filename: name,
|
||||||
arch: archName,
|
arch: archName,
|
||||||
AllTypes: []int{TypeCurrent, TypeRecent, TypeArchive},
|
AllTypes: []int{TypeCurrent, TypeRecent, TypeArchive},
|
||||||
|
TypeCollections: make(map[int]*TimeEntryCollection),
|
||||||
}
|
}
|
||||||
if err := gdb.initDatabase(); err != nil {
|
if err := gdb.initDatabase(); err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
@ -63,11 +65,15 @@ func LoadDatabase(path, name, archName string) (*GimeDB, error) {
|
|||||||
|
|
||||||
// Load a TimeEntry collection from a database
|
// Load a TimeEntry collection from a database
|
||||||
func (gdb *GimeDB) LoadTimeEntryCollection(tp int) *TimeEntryCollection {
|
func (gdb *GimeDB) LoadTimeEntryCollection(tp int) *TimeEntryCollection {
|
||||||
|
if v, ok := gdb.TypeCollections[tp]; ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
ret := new(TimeEntryCollection)
|
ret := new(TimeEntryCollection)
|
||||||
entries := gdb.dbGetAllTimeEntries(tp)
|
entries := gdb.dbGetAllTimeEntries(tp)
|
||||||
for i := range entries {
|
for i := range entries {
|
||||||
ret.Push(&entries[i])
|
ret.Push(&entries[i])
|
||||||
}
|
}
|
||||||
|
gdb.TypeCollections[tp] = ret
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +225,7 @@ func (gdb *GimeDB) dbGetAllTimeEntries(tp int) []TimeEntry {
|
|||||||
ret = append(ret, *te)
|
ret = append(ret, *te)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user