mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	优化批量删除缓存Key代码,防止列表删除了文件还在
This commit is contained in:
		@@ -261,11 +261,6 @@ func (this *FileList) Purge(count int, callback func(hash string) error) (int, e
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		_, err = db.writeDB.Exec(`DELETE FROM "cacheItems" WHERE "hash" IN ('` + strings.Join(hashStrings, "', '") + `')`)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return 0, err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		countFound += len(hashStrings)
 | 
			
		||||
 | 
			
		||||
		// 不在 rows.Next() 循环中操作是为了避免死锁
 | 
			
		||||
@@ -280,6 +275,11 @@ func (this *FileList) Purge(count int, callback func(hash string) error) (int, e
 | 
			
		||||
				return 0, err
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		_, err = db.writeDB.Exec(`DELETE FROM "cacheItems" WHERE "hash" IN ('` + strings.Join(hashStrings, "', '") + `')`)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return 0, err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return countFound, nil
 | 
			
		||||
@@ -301,11 +301,6 @@ func (this *FileList) PurgeLFU(count int, callback func(hash string) error) erro
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		_, err = db.writeDB.Exec(`DELETE FROM "cacheItems" WHERE "hash" IN ('` + strings.Join(hashStrings, "', '") + `')`)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// 不在 rows.Next() 循环中操作是为了避免死锁
 | 
			
		||||
		for _, hash := range hashStrings {
 | 
			
		||||
			_, err = this.remove(hash, true)
 | 
			
		||||
@@ -318,6 +313,11 @@ func (this *FileList) PurgeLFU(count int, callback func(hash string) error) erro
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		_, err = db.writeDB.Exec(`DELETE FROM "cacheItems" WHERE "hash" IN ('` + strings.Join(hashStrings, "', '") + `')`)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user