MCPcopy
hub / github.com/perkeep/perkeep / condRefresh

Method condRefresh

pkg/fs/versions.go:111–194  ·  view source on GitHub ↗

requires n.mu is held

(ctx context.Context)

Source from the content-addressed store, hash-verified

109
110// requires n.mu is held
111func (n *versionsDir) condRefresh(ctx context.Context) error {
112 if n.lastQuery.After(time.Now().Add(-versionsRefreshTime)) {
113 return nil
114 }
115 Logger.Printf("fs.versions: querying")
116
117 var rootRes, impRes *search.WithAttrResponse
118 var grp syncutil.Group
119 grp.Go(func() (err error) {
120 rootRes, err = n.fs.client.GetPermanodesWithAttr(ctx, &search.WithAttrRequest{N: 100, Attr: "camliRoot"})
121 return
122 })
123 grp.Go(func() (err error) {
124 impRes, err = n.fs.client.GetPermanodesWithAttr(ctx, &search.WithAttrRequest{N: 100, Attr: "camliImportRoot"})
125 return
126 })
127 if err := grp.Err(); err != nil {
128 Logger.Printf("fs.versions: GetRecentPermanodes error in ReadDir: %v", err)
129 return err
130 }
131
132 n.m = make(map[string]blob.Ref)
133 if n.children == nil {
134 n.children = make(map[string]fs.Node)
135 }
136
137 dr := &search.DescribeRequest{
138 Depth: 1,
139 }
140 for _, wi := range rootRes.WithAttr {
141 dr.BlobRefs = append(dr.BlobRefs, wi.Permanode)
142 }
143 for _, wi := range impRes.WithAttr {
144 dr.BlobRefs = append(dr.BlobRefs, wi.Permanode)
145 }
146 if len(dr.BlobRefs) == 0 {
147 return nil
148 }
149
150 dres, err := n.fs.client.Describe(ctx, dr)
151 if err != nil {
152 Logger.Printf("Describe failure: %v", err)
153 return err
154 }
155
156 // Roots
157 currentRoots := map[string]bool{}
158 for _, wi := range rootRes.WithAttr {
159 pn := wi.Permanode
160 db := dres.Meta[pn.String()]
161 if db != nil && db.Permanode != nil {
162 name := db.Permanode.Attr.Get("camliRoot")
163 if name != "" {
164 currentRoots[name] = true
165 n.m[name] = pn
166 }
167 }
168 }

Callers 2

ReadDirMethod · 0.95
LookupMethod · 0.95

Calls 8

deleteFunction · 0.85
PrintfMethod · 0.80
DescribeMethod · 0.65
GetMethod · 0.65
AddMethod · 0.45
GetPermanodesWithAttrMethod · 0.45
ErrMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected