(count int, callback func(hash string) error)
| 292 | } |
| 293 | |
| 294 | func (this *SQLiteFileList) PurgeLFU(count int, callback func(hash string) error) error { |
| 295 | count /= CountFileDB |
| 296 | if count <= 0 { |
| 297 | count = 100 |
| 298 | } |
| 299 | |
| 300 | for _, db := range this.dbList { |
| 301 | hashStrings, err := db.ListLFUItems(count) |
| 302 | if err != nil { |
| 303 | return err |
| 304 | } |
| 305 | |
| 306 | if len(hashStrings) == 0 { |
| 307 | continue |
| 308 | } |
| 309 | |
| 310 | // 不在 rows.Next() 循环中操作是为了避免死锁 |
| 311 | for _, hash := range hashStrings { |
| 312 | _, err = this.remove(hash, true) |
| 313 | if err != nil { |
| 314 | return err |
| 315 | } |
| 316 | |
| 317 | err = callback(hash) |
| 318 | if err != nil { |
| 319 | return err |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | _, err = db.writeDB.Exec(`DELETE FROM "cacheItems" WHERE "hash" IN ('` + strings.Join(hashStrings, "', '") + `')`) |
| 324 | if err != nil { |
| 325 | return err |
| 326 | } |
| 327 | } |
| 328 | return nil |
| 329 | } |
| 330 | |
| 331 | func (this *SQLiteFileList) CleanAll() error { |
| 332 | defer this.memoryCache.Clean() |
nothing calls this directly
no test coverage detected