辞書ファイル操作をOperationQueueを使って直列化する #204
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#203 ユーザー辞書が空エントリに戻るバグの修正を試みます。
Issueにあるログにある順番から、おそらくユーザー辞書の書き込みと読み込みがほぼ同時に起こったものと推測します。
a. おそらくここで0バイトだけ読み込んでしまって0エントリに戻った?
このあと書き込みを行う時は0エントリとして書き込んでしまい、それ以降は正常に読み込んでも既存のエントリが消失してしまったと思われます。
macSKKの定期的に保存する処理をバックグラウンド (非mainスレッド) で実行しており、またmacOS 14.6.1では辞書が更新されたイベントを受け取るのもバックグラウンド (非mainスレッド) で呼び出されているようでした。
このPRでは同時実行数を1に制限したOperationQueueを使い読み込みと書き込みを直列化することで、書き込み中に読み込もうとしても書き込みが完了するまでは読み込めないようにします。
また、上記の推測が正しいとして、念の為に0バイトしか読み込めなかったときは読み込みをなかったことにします。