Select Git revision
auxdb.go 5.31 KiB
package auxdbbackend
import (
"context"
"encoding/json"
"log"
"strings"
"sync"
as "git.autistici.org/ai3/accountserver"
"git.autistici.org/ai3/go-common/clientutil"
auxpb "git.autistici.org/ai3/tools/aux-db/proto"
)
// Data type of the webapp-related resources in aux-db.
const auxDbWebappDataType = "cms_info"
// Data type of disk usage resources in aux-db.
const auxDbDiskUsageDataType = "disk_usage"
// AuxWebappBackend looks up website information (cms_info data type) in
// the aux-db service.
//
// A lookup spawns a number of requests for each resource that might
// be involved, but we would like to group requests to aux-db such as
// to minimize their number (and parallelize them). So we generate a
// list of resource IDs to lookup, along with an associated callback
// that will modify the original resource. Then we group them by
// shard, fan out the requests in parallel, and invoke the callbacks
// with the results.
type AuxWebappBackend struct {
as.Backend
auxdbbe clientutil.Backend
}
type wdbTX struct {
as.TX
auxdbbe clientutil.Backend
}
func Wrap(b as.Backend, config *clientutil.BackendConfig) (*AuxWebappBackend, error) {
be, err := clientutil.NewBackend(config)
if err != nil {
return nil, err
}
return &AuxWebappBackend{
Backend: b,
auxdbbe: be,
}, nil
}
func (b *AuxWebappBackend) NewTransaction() (as.TX, error) {
tx, err := b.Backend.NewTransaction()
if err != nil {
return nil, err
}
return &wdbTX{
TX: tx,
auxdbbe: b.auxdbbe,
}, nil
}
func (tx *wdbTX) GetUser(ctx context.Context, name string) (*as.RawUser, error) {
user, err := tx.TX.GetUser(ctx, name)
if err != nil || user == nil {
return user, err
}
// Find all web resources.