<commit_before>/* saves preview images for each tab */

var previewCache = {
  images: {}, // tabId: image
  get: function (tabId) {
    return previewCache.images[tabId]
  },
  set: function (tabId, image) {
    previewCache.images[tabId] = image
  }
}

var savedData = localStorage.getItem('previewCache')

if (savedData) {
  try {
    previewCache.images = JSON.parse(savedData)
  } catch (e) {
    console.warn('discarding preview cache', e)
    previewCache.images = {}
  }
}

setInterval(function () {
  // discard any images for tabs that don't exist any more
  // TODO replace this with an event listener
  for (var tab in previewCache.images) {
    if (!tabs.has(tab)) {
      delete previewCache.images[tab]
    }
  }

  localStorage.setItem('previewCache', JSON.stringify(previewCache.images))
}, 60000)

module.exports = previewCache
<commit_msg>fix preview images being discarded for background tasks<commit_after>/* saves preview images for each tab */

var previewCache = {
  images: {}, // tabId: image
  get: function (tabId) {
    return previewCache.images[tabId]
  },
  set: function (tabId, image) {
    previewCache.images[tabId] = image
  }
}

var savedData = localStorage.getItem('previewCache')

if (savedData) {
  try {
    previewCache.images = JSON.parse(savedData)
  } catch (e) {
    console.warn('discarding preview cache', e)
    previewCache.images = {}
  }
}

setInterval(function () {
  // discard any images for tabs that don't exist any more
  // TODO replace this with an event listener
  for (var tab in previewCache.images) {
    if (!tasks.getTaskContainingTab(tab)) {
      delete previewCache.images[tab]
    }
  }

  localStorage.setItem('previewCache', JSON.stringify(previewCache.images))
}, 60000)

module.exports = previewCache

{'fraction_non_alphanumeric': 0.1204954954954955, 'fraction_numerical': 0.00563063063063063, 'mean_word_length': 3.6036269430051813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6494566', 'n_tokens_mistral': 563, 'n_tokens_neox': 545, 'n_words': 147}