MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / CleanMatchKey

Method CleanMatchKey

internal/caches/list_file_db_sqlite.go:331–374  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

329}
330
331func (this *SQLiteFileListDB) CleanMatchKey(key string) error {
332 if !this.isReady {
333 return nil
334 }
335
336 // 忽略 @GOEDGE_
337 if strings.Contains(key, SuffixAll) {
338 return nil
339 }
340
341 u, err := url.Parse(key)
342 if err != nil {
343 return nil
344 }
345
346 var host = u.Host
347 hostPart, _, err := net.SplitHostPort(host)
348 if err == nil && len(hostPart) > 0 {
349 host = hostPart
350 }
351 if len(host) == 0 {
352 return nil
353 }
354
355 // 转义
356 var queryKey = strings.ReplaceAll(key, "%", "\\%")
357 queryKey = strings.ReplaceAll(queryKey, "_", "\\_")
358 queryKey = strings.Replace(queryKey, "*", "%", 1)
359
360 // TODO 检查大批量数据下的操作性能
361 var unixTime = fasttime.Now().Unix() // 只删除当前的,不删除新的
362
363 _, err = this.writeDB.Exec(`UPDATE "`+this.itemsTableName+`" SET "expiredAt"=0, "staleAt"=? WHERE "host" GLOB ? AND "host" NOT GLOB ? AND "key" LIKE ? ESCAPE '\'`, unixTime+DefaultStaleCacheSeconds, host, "*."+host, queryKey)
364 if err != nil {
365 return err
366 }
367
368 _, err = this.writeDB.Exec(`UPDATE "`+this.itemsTableName+`" SET "expiredAt"=0, "staleAt"=? WHERE "host" GLOB ? AND "host" NOT GLOB ? AND "key" LIKE ? ESCAPE '\'`, unixTime+DefaultStaleCacheSeconds, host, "*."+host, queryKey+SuffixAll+"%")
369 if err != nil {
370 return err
371 }
372
373 return nil
374}
375
376func (this *SQLiteFileListDB) CleanMatchPrefix(prefix string) error {
377 if !this.isReady {

Callers

nothing calls this directly

Calls 5

NowFunction · 0.92
ParseMethod · 0.80
UnixMethod · 0.80
ContainsMethod · 0.45
ExecMethod · 0.45

Tested by

no test coverage detected