Revert "Cache titles to reduce title requests. #2327"
This reverts commit 5c6e8e15bd368ab522749df0ca00d9296384dc5f.
This commit is contained in:
parent
5b805c7b0e
commit
e8db66c516
@ -20,8 +20,6 @@ Embedding =
|
|||||||
for key, service of Embedding.types when service.title?.batchSize
|
for key, service of Embedding.types when service.title?.batchSize
|
||||||
Embedding.flushTitles service.title
|
Embedding.flushTitles service.title
|
||||||
return
|
return
|
||||||
@cache.init Conf['cachedTitles']
|
|
||||||
$.sync 'cachedTitles', @cache.sync
|
|
||||||
|
|
||||||
events: (post) ->
|
events: (post) ->
|
||||||
return if g.VIEW is 'archive'
|
return if g.VIEW is 'archive'
|
||||||
@ -108,9 +106,7 @@ Embedding =
|
|||||||
{key, uid, options, link, post} = data
|
{key, uid, options, link, post} = data
|
||||||
return if not (service = Embedding.types[key].title)
|
return if not (service = Embedding.types[key].title)
|
||||||
$.addClass link, key.toLowerCase()
|
$.addClass link, key.toLowerCase()
|
||||||
if (text = Embedding.cache.get data)
|
if service.batchSize
|
||||||
Embedding.cb.titleText text, data
|
|
||||||
else if service.batchSize
|
|
||||||
(service.queue or= []).push data
|
(service.queue or= []).push data
|
||||||
if service.queue.length >= service.batchSize
|
if service.queue.length >= service.batchSize
|
||||||
Embedding.flushTitles service
|
Embedding.flushTitles service
|
||||||
@ -126,38 +122,6 @@ Embedding =
|
|||||||
return
|
return
|
||||||
CrossOrigin.cache service.api(data.uid for data in queue), cb
|
CrossOrigin.cache service.api(data.uid for data in queue), cb
|
||||||
|
|
||||||
cache: do ->
|
|
||||||
titles = $.dict()
|
|
||||||
newEntries = []
|
|
||||||
init = (data) ->
|
|
||||||
try
|
|
||||||
for {key, uid, text} in data
|
|
||||||
titles["#{key}.#{uid}"] = text
|
|
||||||
return
|
|
||||||
sync = (data) ->
|
|
||||||
try
|
|
||||||
for {key, uid, text} in data
|
|
||||||
k = "#{key}.#{uid}"
|
|
||||||
break if k of titles
|
|
||||||
titles[k] = text
|
|
||||||
return
|
|
||||||
get = ({key, uid}) ->
|
|
||||||
titles["#{key}.#{uid}"]
|
|
||||||
set = ({key, uid}, text) ->
|
|
||||||
titles["#{key}.#{uid}"] = text
|
|
||||||
newEntries.push {key, uid, text}
|
|
||||||
save()
|
|
||||||
save = $.debounce 2 * $.SECOND, ->
|
|
||||||
$.get 'cachedTitles', Conf['cachedTitles'], ({cachedTitles}) ->
|
|
||||||
sync cachedTitles
|
|
||||||
try
|
|
||||||
cachedTitles = newEntries.concat(cachedTitles)[-100..]
|
|
||||||
catch
|
|
||||||
cachedTitles = newEntries
|
|
||||||
newEntries = []
|
|
||||||
$.set 'cachedTitles', cachedTitles
|
|
||||||
{init, sync, get, set, save}
|
|
||||||
|
|
||||||
preview: (data) ->
|
preview: (data) ->
|
||||||
{key, uid, link} = data
|
{key, uid, link} = data
|
||||||
return if not (service = Embedding.types[key].preview)
|
return if not (service = Embedding.types[key].preview)
|
||||||
@ -215,28 +179,25 @@ Embedding =
|
|||||||
title: (req, data) ->
|
title: (req, data) ->
|
||||||
return unless req.status
|
return unless req.status
|
||||||
|
|
||||||
{key, uid} = data
|
{key, uid, options, link, post} = data
|
||||||
{status} = req
|
{status} = req
|
||||||
service = Embedding.types[key].title
|
service = Embedding.types[key].title
|
||||||
|
|
||||||
switch status
|
text = "[#{key}] #{switch status
|
||||||
when 200, 304
|
when 200, 304
|
||||||
text = service.text req.response, uid
|
text = service.text req.response, uid
|
||||||
if typeof text is 'string'
|
if typeof text is 'string'
|
||||||
Embedding.cache.set data, text
|
text
|
||||||
else
|
else
|
||||||
text = link.textContent
|
text = link.textContent
|
||||||
when 404
|
when 404
|
||||||
text = "Not Found"
|
"Not Found"
|
||||||
when 403
|
when 403
|
||||||
text = "Forbidden or Private"
|
"Forbidden or Private"
|
||||||
else
|
else
|
||||||
text = "#{status}'d"
|
"#{status}'d"
|
||||||
Embedding.cb.titleText text, data
|
}"
|
||||||
|
|
||||||
titleText: (text, data) ->
|
|
||||||
{key, link, post} = data
|
|
||||||
text = "[#{key}] #{text}"
|
|
||||||
link.dataset.original = link.textContent
|
link.dataset.original = link.textContent
|
||||||
link.textContent = text
|
link.textContent = text
|
||||||
for post2 in post.clones
|
for post2 in post.clones
|
||||||
|
|||||||
@ -1176,8 +1176,6 @@ Config =
|
|||||||
|
|
||||||
knownBanners: '<%= readJSON("banners.json").join(",") %>'
|
knownBanners: '<%= readJSON("banners.json").join(",") %>'
|
||||||
|
|
||||||
cachedTitles: [[]]
|
|
||||||
|
|
||||||
passMessageClosed: false
|
passMessageClosed: false
|
||||||
|
|
||||||
'Prerequest Captcha': false
|
'Prerequest Captcha': false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user