Doing some work
This commit is contained in:
26
data/repo.go
26
data/repo.go
@@ -21,9 +21,33 @@ THE SOFTWARE.
|
||||
*/
|
||||
package data
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.bullercodeworks.com/brian/expds/data/models"
|
||||
)
|
||||
|
||||
type Repo struct {
|
||||
LoadedPDSs map[string]*models.Pds
|
||||
|
||||
BestBy time.Duration
|
||||
}
|
||||
|
||||
func NewRepo() (*Repo, error) {
|
||||
return &Repo{}, nil
|
||||
return &Repo{
|
||||
LoadedPDSs: make(map[string]*models.Pds),
|
||||
BestBy: time.Minute * 15,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Repo) GetPDS(atId string) (*models.Pds, error) {
|
||||
if p, ok := r.LoadedPDSs[atId]; ok && time.Since(p.RefreshTime) < r.BestBy {
|
||||
return p, nil
|
||||
}
|
||||
p, err := models.NewPdsFromDid(atId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.LoadedPDSs[atId] = p
|
||||
return p, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user