| 45 | } |
| 46 | |
| 47 | func (this *SQLiteFileListHashMap) Load(db *SQLiteFileListDB) error { |
| 48 | // 如果系统内存过小,我们不缓存 |
| 49 | if memutils.SystemMemoryGB() < 3 { |
| 50 | return nil |
| 51 | } |
| 52 | |
| 53 | this.isAvailable = true |
| 54 | |
| 55 | var lastId int64 |
| 56 | var maxLoops = 50_000 |
| 57 | for { |
| 58 | hashList, maxId, err := db.ListHashes(lastId) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | if len(hashList) == 0 { |
| 63 | break |
| 64 | } |
| 65 | this.AddHashes(hashList) |
| 66 | lastId = maxId |
| 67 | |
| 68 | maxLoops-- |
| 69 | if maxLoops <= 0 { |
| 70 | break |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | this.isReady = true |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | func (this *SQLiteFileListHashMap) Add(hash string) { |
| 79 | if !this.isAvailable { |