Skip to content

Commit 1b61adf

Browse files
committed
reduce write-lock duration, a few quick memory operations for most calls within the write-lock time
1 parent b4c1230 commit 1b61adf

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

modules/translation/i18n/i18n.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ func (l *locale) tryTr(trKey string, trArgs ...interface{}) (msg string, found b
147147
if l.store.reloadMu != nil {
148148
now := time.Now()
149149
if now.Sub(l.lastReloadCheckTime) >= time.Second && l.sourceFileInfo != nil && l.sourceFileName != "" {
150+
sourceFileInfo, err := os.Stat(l.sourceFileName)
150151
l.store.reloadMu.RUnlock() // if the locale file should be reloaded, then we release the read-lock
151152
l.store.reloadMu.Lock() // and acquire the write-lock
152153
l.lastReloadCheckTime = now
153-
if sourceFileInfo, err := os.Stat(l.sourceFileName); err == nil && !sourceFileInfo.ModTime().Equal(l.sourceFileInfo.ModTime()) {
154+
if err == nil && !sourceFileInfo.ModTime().Equal(l.sourceFileInfo.ModTime()) {
154155
if err = l.store.reloadLocaleByIni(l.langName, l.sourceFileName); err == nil {
155156
l.sourceFileInfo = sourceFileInfo
156157
} else {

0 commit comments

Comments
 (0)