Do not save captchas to disk or share them between tabs. They are too short-lived to be worth it now. This should reduce associated I/O errors.

This commit is contained in:
ccd0 2018-01-24 16:49:35 -08:00
parent abbababda9
commit 3072550cdb
2 changed files with 1 additions and 15 deletions

View File

@ -1,9 +1,5 @@
Captcha.cache =
init: ->
$.get 'captchas', [], ({captchas}) =>
@sync captchas
@clear()
$.sync 'captchas', @sync.bind(@)
$.on d, 'SaveCaptcha', (e) =>
@save e.detail
@ -19,38 +15,28 @@ Captcha.cache =
QR.posts.length > 1 or Conf['Auto-load captcha'] or QR.posts[0].com or QR.posts[0].file
)
sync: (captchas=[]) ->
captchas = [] unless captchas instanceof Array
@captchas = captchas
@count()
getOne: (isReply) ->
@clear()
i = @captchas.findIndex((x) -> isReply or !x.challenge?)
if i >= 0
captcha = @captchas.splice(i, 1)[0]
$.set 'captchas', @captchas
@count()
captcha
else
null
save: (captcha) ->
$.forceSync 'captchas'
@captchas.push captcha
@captchas.sort (a, b) -> a.timeout - b.timeout
$.set 'captchas', @captchas
@count()
clear: ->
$.forceSync 'captchas'
if @captchas.length
now = Date.now()
for captcha, i in @captchas
break if captcha.timeout > now
if i
@captchas = @captchas[i..]
$.set 'captchas', @captchas
@count()
count: ->

View File

@ -664,7 +664,7 @@ else
# XXX https://github.com/greasemonkey/greasemonkey/issues/2033
# Also support case where GM_listValues is not defined.
$.delete Object.keys(Conf)
$.delete ['previousversion', 'QR Size', 'captchas', 'QR.persona', 'hiddenPSA']
$.delete ['previousversion', 'QR Size', 'QR.persona', 'hiddenPSA']
try
$.delete $.listValues().map (key) -> key.replace g.NAMESPACE, ''
cb?()