Revert "Cache titles to reduce title requests. #2327"

This reverts commit 5c6e8e15bd368ab522749df0ca00d9296384dc5f.
This commit is contained in:
ccd0 2020-04-26 22:03:53 -07:00
parent 5b805c7b0e
commit e8db66c516
2 changed files with 8 additions and 49 deletions

View File

@ -20,8 +20,6 @@ Embedding =
for key, service of Embedding.types when service.title?.batchSize
Embedding.flushTitles service.title
return
@cache.init Conf['cachedTitles']
$.sync 'cachedTitles', @cache.sync
events: (post) ->
return if g.VIEW is 'archive'
@ -108,9 +106,7 @@ Embedding =
{key, uid, options, link, post} = data
return if not (service = Embedding.types[key].title)
$.addClass link, key.toLowerCase()
if (text = Embedding.cache.get data)
Embedding.cb.titleText text, data
else if service.batchSize
if service.batchSize
(service.queue or= []).push data
if service.queue.length >= service.batchSize
Embedding.flushTitles service
@ -126,38 +122,6 @@ Embedding =
return
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) ->
{key, uid, link} = data
return if not (service = Embedding.types[key].preview)
@ -215,28 +179,25 @@ Embedding =
title: (req, data) ->
return unless req.status
{key, uid} = data
{key, uid, options, link, post} = data
{status} = req
service = Embedding.types[key].title
switch status
text = "[#{key}] #{switch status
when 200, 304
text = service.text req.response, uid
if typeof text is 'string'
Embedding.cache.set data, text
text
else
text = link.textContent
when 404
text = "Not Found"
"Not Found"
when 403
text = "Forbidden or Private"
"Forbidden or Private"
else
text = "#{status}'d"
Embedding.cb.titleText text, data
"#{status}'d"
}"
titleText: (text, data) ->
{key, link, post} = data
text = "[#{key}] #{text}"
link.dataset.original = link.textContent
link.textContent = text
for post2 in post.clones

View File

@ -1176,8 +1176,6 @@ Config =
knownBanners: '<%= readJSON("banners.json").join(",") %>'
cachedTitles: [[]]
passMessageClosed: false
'Prerequest Captcha': false