Allow nil Snapshot for most ops, CRUD for collection

This commit is contained in:
jdl
2023-11-21 17:41:55 +01:00
parent 3c9e5505ab
commit 9078335d70
8 changed files with 110 additions and 98 deletions

View File

@@ -136,8 +136,8 @@ func (db DataDB) modifyOnce() {
func (db DataDB) ComputeCRC(tx *mdb.Snapshot) uint32 {
h := crc32.NewIEEE()
for dataID := uint64(1); dataID < 10; dataID++ {
d, ok := db.Datas.ByID.Get(tx, &DataItem{ID: dataID})
if !ok {
d := db.Datas.ByID.Get(tx, &DataItem{ID: dataID})
if d == nil {
continue
}
h.Write(d.Data)
@@ -146,8 +146,8 @@ func (db DataDB) ComputeCRC(tx *mdb.Snapshot) uint32 {
}
func (db DataDB) ReadCRC(tx *mdb.Snapshot) uint32 {
r, ok := db.CRCs.ByID.Get(tx, &CRCItem{ID: 1})
if !ok {
r := db.CRCs.ByID.Get(tx, &CRCItem{ID: 1})
if r == nil {
return 0
}
return r.CRC32