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:
parent
abbababda9
commit
3072550cdb
@ -1,9 +1,5 @@
|
|||||||
Captcha.cache =
|
Captcha.cache =
|
||||||
init: ->
|
init: ->
|
||||||
$.get 'captchas', [], ({captchas}) =>
|
|
||||||
@sync captchas
|
|
||||||
@clear()
|
|
||||||
$.sync 'captchas', @sync.bind(@)
|
|
||||||
$.on d, 'SaveCaptcha', (e) =>
|
$.on d, 'SaveCaptcha', (e) =>
|
||||||
@save e.detail
|
@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
|
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) ->
|
getOne: (isReply) ->
|
||||||
@clear()
|
@clear()
|
||||||
i = @captchas.findIndex((x) -> isReply or !x.challenge?)
|
i = @captchas.findIndex((x) -> isReply or !x.challenge?)
|
||||||
if i >= 0
|
if i >= 0
|
||||||
captcha = @captchas.splice(i, 1)[0]
|
captcha = @captchas.splice(i, 1)[0]
|
||||||
$.set 'captchas', @captchas
|
|
||||||
@count()
|
@count()
|
||||||
captcha
|
captcha
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
|
|
||||||
save: (captcha) ->
|
save: (captcha) ->
|
||||||
$.forceSync 'captchas'
|
|
||||||
@captchas.push captcha
|
@captchas.push captcha
|
||||||
@captchas.sort (a, b) -> a.timeout - b.timeout
|
@captchas.sort (a, b) -> a.timeout - b.timeout
|
||||||
$.set 'captchas', @captchas
|
|
||||||
@count()
|
@count()
|
||||||
|
|
||||||
clear: ->
|
clear: ->
|
||||||
$.forceSync 'captchas'
|
|
||||||
if @captchas.length
|
if @captchas.length
|
||||||
now = Date.now()
|
now = Date.now()
|
||||||
for captcha, i in @captchas
|
for captcha, i in @captchas
|
||||||
break if captcha.timeout > now
|
break if captcha.timeout > now
|
||||||
if i
|
if i
|
||||||
@captchas = @captchas[i..]
|
@captchas = @captchas[i..]
|
||||||
$.set 'captchas', @captchas
|
|
||||||
@count()
|
@count()
|
||||||
|
|
||||||
count: ->
|
count: ->
|
||||||
|
|||||||
@ -664,7 +664,7 @@ else
|
|||||||
# XXX https://github.com/greasemonkey/greasemonkey/issues/2033
|
# XXX https://github.com/greasemonkey/greasemonkey/issues/2033
|
||||||
# Also support case where GM_listValues is not defined.
|
# Also support case where GM_listValues is not defined.
|
||||||
$.delete Object.keys(Conf)
|
$.delete Object.keys(Conf)
|
||||||
$.delete ['previousversion', 'QR Size', 'captchas', 'QR.persona', 'hiddenPSA']
|
$.delete ['previousversion', 'QR Size', 'QR.persona', 'hiddenPSA']
|
||||||
try
|
try
|
||||||
$.delete $.listValues().map (key) -> key.replace g.NAMESPACE, ''
|
$.delete $.listValues().map (key) -> key.replace g.NAMESPACE, ''
|
||||||
cb?()
|
cb?()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user