<commit_before>/*global indexedDB, setTimeout */

class Database {
    // name: string
    // version: number
    // setup: (db,oldVersion,newVersion)
    // needsUpdate (optional)
    constructor(mixin) {
        this._db = null;
        Object.assign(this, mixin);
    }

    needsUpdate() {}

    open() {
        if (this._db) {
            return this._db;
        }
        const _db = new Promise((resolve, reject) => {
            const name = this.name;
            const request = indexedDB.open(name, this.version);
            let didTimeOut = false;
            setTimeout(() => {
                didTimeOut = true;
                reject(new Error(`Timed out trying to open ${name}`));
            }, 2000);
            request.onupgradeneeded = (event) => {
                const db = request.result;
                if (didTimeOut) {
                    request.transaction.abort();
                    db.close();
                } else {
                    this.setup(db, event.newVersion, event.oldVersion);
                }
            };
            request.onsuccess = () => {
                const db = request.result;
                if (didTimeOut) {
                    db.close();
                } else {
                    db.onversionchange = () => this.needsUpdate();
                    resolve(db);
                }
            };
            request.onerror = () => reject(request.errorCode);
        });
        _db.catch(() => {
            if (this._db === _db) {
                this._db = null;
            }
        });
        this._db = _db;
        return _db;
    }

    // Mode = readwrite or readonly
    async transaction(storeNames, mode, fn) {
        const db = await this.open();
        return new Promise((resolve, reject) => {
            const transaction = db.transaction(storeNames, mode);
            transaction.onabort = () => reject(transaction.error);
            transaction.oncomplete = () => resolve();
            fn(transaction);
        });<commit_msg>Remove timeout from Database opening<commit_after>/*global indexedDB */

class Database {
    // name: string
    // version: number
    // setup: (db,oldVersion,newVersion)
    // needsUpdate (optional)
    constructor(mixin) {
        this._db = null;
        Object.assign(this, mixin);
    }

    needsUpdate() {}

    open() {
        if (this._db) {
            return this._db;
        }
        const _db = new Promise((resolve, reject) => {
            const name = this.name;
            const request = indexedDB.open(name, this.version);
            request.onupgradeneeded = (event) => {
                const db = request.result;
                this.setup(db, event.newVersion, event.oldVersion);
            };
            request.onsuccess = () => {
                const db = request.result;
                db.onversionchange = () => this.needsUpdate();
                resolve(db);
            };
            request.onerror = () => reject(request.errorCode);
        });
        _db.catch(() => {
            if (this._db === _db) {
                this._db = null;
            }
        });
        this._db = _db;
        return _db;
    }

    // Mode = readwrite or readonly
    async transaction(storeNames, mode, fn) {
        const db = await this.open();
        return new Promise((resolve, reject) => {
            const transaction = db.transaction(storeNames, mode);
            transaction.onabort = () => reject(transaction.error);
            transaction.oncomplete = () => resolve();
            fn(transaction);
        });
{'fraction_non_alphanumeric': 0.1277545327754533, 'fraction_numerical': 0.0011157601115760112, 'mean_word_length': 1.4197031039136303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '3920052', 'n_tokens_mistral': 959, 'n_tokens_neox': 923, 'n_words': 202}