mirror of
https://github.com/safing/portbase
synced 2025-09-04 03:29:59 +00:00
Move GetMeta storage API to separate interface
This commit is contained in:
parent
a41ea62d2d
commit
5dc39685da
2 changed files with 26 additions and 8 deletions
|
@ -55,7 +55,7 @@ func (c *Controller) Get(key string) (record.Record, error) {
|
||||||
r, err := c.storage.Get(key)
|
r, err := c.storage.Get(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// replace not found error
|
// replace not found error
|
||||||
if err == storage.ErrNotFound {
|
if errors.Is(err, storage.ErrNotFound) {
|
||||||
return nil, ErrNotFound
|
return nil, ErrNotFound
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -82,13 +82,27 @@ func (c *Controller) GetMeta(key string) (*record.Meta, error) {
|
||||||
return nil, ErrShuttingDown
|
return nil, ErrShuttingDown
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := c.storage.GetMeta(key)
|
var m *record.Meta
|
||||||
if err != nil {
|
var err error
|
||||||
// replace not found error
|
if metaDB, ok := c.storage.(storage.MetaHandler); ok {
|
||||||
if err == storage.ErrNotFound {
|
m, err = metaDB.GetMeta(key)
|
||||||
return nil, ErrNotFound
|
if err != nil {
|
||||||
|
// replace not found error
|
||||||
|
if errors.Is(err, storage.ErrNotFound) {
|
||||||
|
return nil, ErrNotFound
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, err
|
} else {
|
||||||
|
r, err := c.storage.Get(key)
|
||||||
|
if err != nil {
|
||||||
|
// replace not found error
|
||||||
|
if errors.Is(err, storage.ErrNotFound) {
|
||||||
|
return nil, ErrNotFound
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
m = r.Meta()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !m.CheckValidity() {
|
if !m.CheckValidity() {
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
// Primary Interface
|
// Primary Interface
|
||||||
Get(key string) (record.Record, error)
|
Get(key string) (record.Record, error)
|
||||||
GetMeta(key string) (*record.Meta, error)
|
|
||||||
Put(m record.Record) (record.Record, error)
|
Put(m record.Record) (record.Record, error)
|
||||||
Delete(key string) error
|
Delete(key string) error
|
||||||
Query(q *query.Query, local, internal bool) (*iterator.Iterator, error)
|
Query(q *query.Query, local, internal bool) (*iterator.Iterator, error)
|
||||||
|
@ -27,6 +26,11 @@ type Interface interface {
|
||||||
MaintainRecordStates(ctx context.Context, purgeDeletedBefore time.Time, shadowDelete bool) error
|
MaintainRecordStates(ctx context.Context, purgeDeletedBefore time.Time, shadowDelete bool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maintainer defines the database storage API for backends that support optimized fetching of only the metadata.
|
||||||
|
type MetaHandler interface {
|
||||||
|
GetMeta(key string) (*record.Meta, error)
|
||||||
|
}
|
||||||
|
|
||||||
// Maintainer defines the database storage API for backends that require regular maintenance.
|
// Maintainer defines the database storage API for backends that require regular maintenance.
|
||||||
type Maintainer interface {
|
type Maintainer interface {
|
||||||
Maintain(ctx context.Context) error
|
Maintain(ctx context.Context) error
|
||||||
|
|
Loading…
Add table
Reference in a new issue