Fix locking (#1141)

* Fix unprotected section

* Optimize lock where only reads are performed
This commit is contained in:
Aaron Wood 2021-03-28 10:51:38 -07:00 committed by GitHub
parent 84a764ede2
commit cabee7ab61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 5 deletions

View file

@ -52,13 +52,12 @@ func (m *Files) Init() error {
// Done should be called after all files have been processed.
func (m *Files) Done() {
m.mutex.Lock()
defer m.mutex.Unlock()
if (len(m.files) - m.count) == 0 {
return
}
m.mutex.Lock()
defer m.mutex.Unlock()
m.count = 0
m.files = make(query.FileMap)
}

View file

@ -61,8 +61,8 @@ func (m *Photos) Remove(takenAt time.Time, cellId string) {
func (m *Photos) Find(takenAt time.Time, cellId string) uint {
key := entity.MapKey(takenAt, cellId)
m.mutex.Lock()
defer m.mutex.Unlock()
m.mutex.RLock()
defer m.mutex.RUnlock()
return m.photos[key]
}