<commit_before>import {get as getFromEs,
        put as putInEs,
        contains as inEs} from 'entity-store';
import {get as getFromQc,
        invalidate,
        put as putInQc,
        contains as inQc,
        getValue} from 'query-cache';
import {passThrough, compose, prop} from 'fp';
import {addId, removeId} from 'id-helper';

const getTtl = e => (e.ttl || 0) * 1000;

// Entity -> Int -> Bool
const hasExpired = (e, timestamp) => {
    return (Date.now() - timestamp) > getTtl(e);
};

const decorateReadSingle = (c, es, qc, e, aFn) => {
    return (id) => {
        if (inEs(es, e, id) && !aFn.alwaysGetFreshData) {
            const v = getFromEs(es, e, id);
            if (!hasExpired(e, v.timestamp)) {
                return Promise.resolve(removeId(v.value));
            }
        }

        return aFn(id).then(passThrough(compose(putInEs(es, e), addId(c, aFn, id))))
                      .then(passThrough(() => invalidate(qc, e, aFn)));
    };
};

const decorateReadQuery = (c, es, qc, e, aFn) => {
    return (...args) => {
        if (inQc(qc, e, aFn, args) && !aFn.alwaysGetFreshData) {
            const v = getFromQc(qc, e, aFn, args);
            if (!hasExpired(e, v.timestamp)) {
                return Promise.resolve(removeId(getValue(v.value)));
            }
        }

        return aFn(...args)
                   .then(passThrough(compose(putInQc(qc, e, aFn, args), addId(c, aFn, args))))<commit_msg>update default TTL to be 300 seconds<commit_after>import {get as getFromEs,
        put as putInEs,
        contains as inEs} from 'entity-store';
import {get as getFromQc,
        invalidate,
        put as putInQc,
        contains as inQc,
        getValue} from 'query-cache';
import {passThrough, compose} from 'fp';
import {addId, removeId} from 'id-helper';

const getTtl = e => (e.ttl || 300) * 1000;

// Entity -> Int -> Bool
const hasExpired = (e, timestamp) => {
    return (Date.now() - timestamp) > getTtl(e);
};

const decorateReadSingle = (c, es, qc, e, aFn) => {
    return (id) => {
        if (inEs(es, e, id) && !aFn.alwaysGetFreshData) {
            const v = getFromEs(es, e, id);
            if (!hasExpired(e, v.timestamp)) {
                return Promise.resolve(removeId(v.value));
            }
        }

        return aFn(id).then(passThrough(compose(putInEs(es, e), addId(c, aFn, id))))
                      .then(passThrough(() => invalidate(qc, e, aFn)));
    };
};

const decorateReadQuery = (c, es, qc, e, aFn) => {
    return (...args) => {
        if (inQc(qc, e, aFn, args) && !aFn.alwaysGetFreshData) {
            const v = getFromQc(qc, e, aFn, args);
            if (!hasExpired(e, v.timestamp)) {
                return Promise.resolve(removeId(getValue(v.value)));
            }
        }

        return aFn(...args)
                   .then(passThrough(compose(putInQc(qc, e, aFn, args), addId(c, aFn, args))))
{'fraction_non_alphanumeric': 0.1599309153713299, 'fraction_numerical': 0.0051813471502590676, 'mean_word_length': 2.196467991169978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '6018809', 'n_tokens_mistral': 1043, 'n_tokens_neox': 989, 'n_words': 250}