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

Method Exist

internal/caches/list_file_sqlite.go:134–171  ·  view source on GitHub ↗
(hash string)

Source from the content-addressed store, hash-verified

132}
133
134func (this *SQLiteFileList) Exist(hash string) (bool, int64, error) {
135 var db = this.GetDB(hash)
136
137 if !db.IsReady() {
138 return false, -1, nil
139 }
140
141 // 如果Hash列表里不存在,那么必然不存在
142 if !db.hashMap.Exist(hash) {
143 return false, -1, nil
144 }
145
146 var item = this.memoryCache.Read(hash)
147 if item != nil {
148 return true, -1, nil
149 }
150
151 var row = db.existsByHashStmt.QueryRow(hash, time.Now().Unix())
152 if row.Err() != nil {
153 return false, -1, nil
154 }
155
156 var expiredAt int64
157 err := row.Scan(&expiredAt)
158 if err != nil {
159 if errors.Is(err, sql.ErrNoRows) {
160 err = nil
161 }
162 return false, -1, err
163 }
164
165 if expiredAt <= fasttime.Now().Unix() {
166 return false, -1, nil
167 }
168
169 this.memoryCache.Write(hash, zero.Zero{}, this.maxExpiresAtForMemoryCache(expiredAt))
170 return true, -1, nil
171}
172
173func (this *SQLiteFileList) ExistQuick(hash string) (isReady bool, found bool) {
174 var db = this.GetDB(hash)

Callers

nothing calls this directly

Calls 9

GetDBMethod · 0.95
NowFunction · 0.92
UnixMethod · 0.80
IsReadyMethod · 0.65
ExistMethod · 0.65
ReadMethod · 0.65
WriteMethod · 0.65
QueryRowMethod · 0.45

Tested by

no test coverage detected