| 329 | } |
| 330 | |
| 331 | func (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 | |
| 376 | func (this *SQLiteFileListDB) CleanMatchPrefix(prefix string) error { |
| 377 | if !this.isReady { |