mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 08:03:42 -05:00
fix caching logic to include valid words, as well as mispellings
include logging of cache hits
This commit is contained in:
parent
10c3d3eb70
commit
5ba5fd5533
1 changed files with 16 additions and 4 deletions
|
@ -2,6 +2,7 @@ async = require "async"
|
||||||
_ = require "underscore"
|
_ = require "underscore"
|
||||||
ASpellWorkerPool = require "./ASpellWorkerPool"
|
ASpellWorkerPool = require "./ASpellWorkerPool"
|
||||||
LRU = require "lru-cache"
|
LRU = require "lru-cache"
|
||||||
|
logger = require 'logger-sharelatex'
|
||||||
|
|
||||||
cache = LRU(10000)
|
cache = LRU(10000)
|
||||||
|
|
||||||
|
@ -12,14 +13,25 @@ class ASpellRunner
|
||||||
#output = @removeAspellHeader(output)
|
#output = @removeAspellHeader(output)
|
||||||
suggestions = @getSuggestions(output)
|
suggestions = @getSuggestions(output)
|
||||||
results = []
|
results = []
|
||||||
|
hits = 0
|
||||||
for word, i in words
|
for word, i in words
|
||||||
key = language + ':' + word
|
key = language + ':' + word
|
||||||
cached = cache.get(key)
|
cached = cache.get(key)
|
||||||
if cached?
|
if cached?
|
||||||
results.push index: i, suggestions: cached
|
hits++
|
||||||
else if suggestions[word]?
|
if cached == true
|
||||||
cache.set(key, suggestions[word])
|
# valid word, no need to do anything
|
||||||
results.push index: i, suggestions: suggestions[word]
|
continue
|
||||||
|
else
|
||||||
|
results.push index: i, suggestions: cached
|
||||||
|
else
|
||||||
|
if suggestions[word]?
|
||||||
|
cache.set(key, suggestions[word])
|
||||||
|
results.push index: i, suggestions: suggestions[word]
|
||||||
|
else
|
||||||
|
# a valid word, but uncached
|
||||||
|
cache.set(key, true)
|
||||||
|
logger.log hits: hits, total: words.length, hitrate: hits/words.length, "cache hit rate"
|
||||||
callback null, results
|
callback null, results
|
||||||
|
|
||||||
getSuggestions: (output) ->
|
getSuggestions: (output) ->
|
||||||
|
|
Loading…
Reference in a new issue