aboutsummaryrefslogtreecommitdiffstats
path: root/public/assets
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2014-07-13 22:27:18 -0700
committerAdam Soltys <[email protected]>2014-07-13 22:48:43 -0700
commit60029a8f0aa6c8263c0d04e13f00b5c17e8293b3 (patch)
tree07cda37f934bea0d22241acc2031cd3528e2dd59 /public/assets
parent5285fd7af9a5ac71c75bdd6b0fa72de213792e50 (diff)
downloadcoinos-server-60029a8f0aa6c8263c0d04e13f00b5c17e8293b3.tar.gz
coinos-server-60029a8f0aa6c8263c0d04e13f00b5c17e8293b3.zip
Update bootstrap CSS
Diffstat (limited to 'public/assets')
0 files changed, 0 insertions, 0 deletions
old } /* Name.Exception */ .highlight .nf { color: #06B; font-weight: bold } /* Name.Function */ .highlight .nl { color: #369; font-style: italic } /* Name.Label */ .highlight .nn { color: #B06; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #369; font-weight: bold } /* Name.Property */ .highlight .nt { color: #B06; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #369 } /* Name.Variable */ .highlight .ow { color: #080 } /* Operator.Word */ .highlight .w { color: #BBB } /* Text.Whitespace */ .highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */ .highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */ .highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
// Disposable public feed cache. Budget is conservative UTF-16 storage bytes.
// The feeds read most recently keep a full page; the rest keep a few seed
// posts, so switching to any feed paints something before the relays answer.
export const FEED_CACHE_POSTS = 30;
export const FEED_SEED_POSTS = 5;
const FULL_FEEDS = 4, MAX_FEEDS = 12, MAX_UNITS = 256_000, MAX_AGE = 7 * 86400_000;
export function createFeedCache(storage, prefix, now = Date.now) {
  const keyOf = (id) => id === 'following' ? prefix : prefix + ':' + id;
  const valid = (e) => (e?.kind === 1 || e?.kind === 1068) && typeof e.id === 'string' && typeof e.pubkey === 'string'
    && typeof e.content === 'string' && Number.isFinite(e.created_at) && Array.isArray(e.tags);
  function compact(notes, max = FEED_CACHE_POSTS) {
    const kept = []; let size = 0;
    for (const e of (Array.isArray(notes) ? notes : []).filter(valid).sort((a, b) => b.created_at - a.created_at)) {
      const cost = JSON.stringify(e).length;
      if (size + cost > MAX_UNITS - 1000) continue;
      kept.push(e); size += cost;
      if (kept.length === max) break;
    }
    return kept;
  }
  function sweep(preferred) {
    const entries = [];
    for (let i = 0; i < storage.length; i++) {
      const key = storage.key(i);
      if (key !== prefix && !key?.startsWith(prefix + ':')) continue;
      try {
        const text = storage.getItem(key);
        const raw = JSON.parse(text);
        const entry = Array.isArray(raw) ? { at: now(), notes: raw } : raw;
        if (!entry || !Number.isFinite(entry.at) || now() - entry.at > MAX_AGE) entries.push({ key });
        else entries.push({ key, text, entry });
      } catch { entries.push({ key }); }
    }
    // A feed that was read beats one only warmed in the background (seed).
    entries.sort((a, b) => (b.key === preferred) - (a.key === preferred)
      || (!a.entry?.seed) - (!b.entry?.seed) || (b.entry?.at || 0) - (a.entry?.at || 0));
    let units = 0, count = 0;
    for (const e of entries) {
      const max = count < FULL_FEEDS && !e.entry?.seed ? FEED_CACHE_POSTS : FEED_SEED_POSTS;
      const value = e.entry && { at: e.entry.at, notes: compact(e.entry.notes, max), ...(e.entry.seed ? { seed: true } : {}) };
      const json = value && JSON.stringify(value);
      if (!json || count >= MAX_FEEDS || units + json.length > MAX_UNITS) storage.removeItem(e.key);
      else { if (e.text !== json) storage.setItem(e.key, json); units += json.length; count++; }
    }
  }
  const peek = (id) => { try { return JSON.parse(storage.getItem(keyOf(id)) || 'null'); } catch { return null; } };
  return {
    read(id) {
      try {
        sweep(keyOf(id));
        const value = JSON.parse(storage.getItem(keyOf(id)) || 'null');
        if (!value) return [];
        value.at = now(); storage.setItem(keyOf(id), JSON.stringify(value));
        return value.notes;
      } catch { return []; }
    },
    save(id, notes) {
      try { storage.setItem(keyOf(id), JSON.stringify({ at: now(), notes: compact(notes) })); sweep(keyOf(id)); } catch {}
    },
    // Whether a feed already has posts on disk (without counting as a read).
    has: (id) => !!peek(id)?.notes?.length,
    // A few posts fetched ahead for a feed not yet opened. Never replaces
    // posts a read left behind, and ranks below every feed that was read.
    seed(id, notes) {
      try {
        if (peek(id)?.notes?.length) return;
        storage.setItem(keyOf(id), JSON.stringify({ at: now(), seed: true, notes: compact(notes, FEED_SEED_POSTS) }));
        sweep(null);
      } catch {}
    },
  };
}