<commit_before>var gallery = {};
var indexedDB = window.mozIndexedDB;

gallery.indexedDB = {};
gallery.indexedDB.db = null;
gallery.indexedDB.upgraded = false;

/**
 * Database Error
 */
gallery.indexedDB.onerror = function(e) {
  console.log("Database error: ", e);
}

/**
 * Create IndexedDB Stores
 */
gallery.indexedDB.createStores = function() {
    var db = gallery.indexedDB.db;

    if(db.objectStoreNames.contains("thumbnails")) {
      db.deleteObjectStore("thumbnails");
    }
    var store = db.createObjectStore("thumbnails", {keyPath: "id"});
    if(db.objectStoreNames.contains("photos")) {
      db.deleteObjectStore("photos");
    }
    var store = db.createObjectStore("photos", {keyPath: "id"});
}

/**
 * Open Database
 */
gallery.indexedDB.open = function() {
  var request = indexedDB.open("gallery", 18);

  // For latest version of IndexedDB API
  request.onupgradeneeded = function(e) {
    gallery.indexedDB.db = e.target.result;
    gallery.indexedDB.createStores();
    gallery.indexedDB.upgraded = true;
  }

  request.onsuccess = function(e) {
    gallery.indexedDB.db = e.target.result;
    
    // For older version of IndexedDB API
    var db = gallery.indexedDB.db;
    if(typeof db.setVersion == 'function') {
      var version = "18";
      var db = gallery.indexedDB.db;
      if(version != db.version) {
        var setVrequest = db.setVersion(version);
        setVrequest.onerror = gallery.indexedDB.onerror;
  
        setVrequest.onsuccess = function(e) {
          gallery.indexedDB.createStores();
          gallery.indexedDB.populateSampleData();
        };
      }
    }

    // Populate sample data if upgrade has taken place
    if (gallery.indexedDB.upgraded) {
      gallery.indexedDB.populateSampleData();
      gallery.indexedDB.upgraded = false;
    } else {
      gallery.indexedDB.getAllPhotos();
    }
  }

  request.onerror = gallery.indexedDB.onerror;
};

/**
 * Populate Sample Data
 */
gallery.indexedDB.populateSampleData = function() {
  // Set up the transaction
  var db = gallery.indexedDB.db;
  var trans = db.transaction(["thumbnails", "photos"], IDBTransaction.READ_WRITE);<commit_msg>Decremented gallery DB version number back to something more sane<commit_after>var gallery = {};
var indexedDB = window.mozIndexedDB;

gallery.indexedDB = {};
gallery.indexedDB.db = null;
gallery.indexedDB.upgraded = false;

/**
 * Database Error
 */
gallery.indexedDB.onerror = function(e) {
  console.log("Database error: ", e);
}

/**
 * Create IndexedDB Stores
 */
gallery.indexedDB.createStores = function() {
    var db = gallery.indexedDB.db;

    if(db.objectStoreNames.contains("thumbnails")) {
      db.deleteObjectStore("thumbnails");
    }
    var store = db.createObjectStore("thumbnails", {keyPath: "id"});
    if(db.objectStoreNames.contains("photos")) {
      db.deleteObjectStore("photos");
    }
    var store = db.createObjectStore("photos", {keyPath: "id"});
}

/**
 * Open Database
 */
gallery.indexedDB.open = function() {
  var request = indexedDB.open("gallery", 2);

  // For latest version of IndexedDB API
  request.onupgradeneeded = function(e) {
    gallery.indexedDB.db = e.target.result;
    gallery.indexedDB.createStores();
    gallery.indexedDB.upgraded = true;
  }

  request.onsuccess = function(e) {
    gallery.indexedDB.db = e.target.result;
    
    // For older version of IndexedDB API
    var db = gallery.indexedDB.db;
    if(typeof db.setVersion == 'function') {
      var version = "2";
      var db = gallery.indexedDB.db;
      if(version != db.version) {
        var setVrequest = db.setVersion(version);
        setVrequest.onerror = gallery.indexedDB.onerror;
  
        setVrequest.onsuccess = function(e) {
          gallery.indexedDB.createStores();
          gallery.indexedDB.populateSampleData();
        };
      }
    }

    // Populate sample data if upgrade has taken place
    if (gallery.indexedDB.upgraded) {
      gallery.indexedDB.populateSampleData();
      gallery.indexedDB.upgraded = false;
    } else {
      gallery.indexedDB.getAllPhotos();
    }
  }

  request.onerror = gallery.indexedDB.onerror;
};

/**
 * Populate Sample Data
 */
gallery.indexedDB.populateSampleData = function() {
  // Set up the transaction
  var db = gallery.indexedDB.db;
  var trans = db.transaction(["thumbnails", "photos"], IDBTransaction.READ_WRITE);
{'fraction_non_alphanumeric': 0.1349862258953168, 'fraction_numerical': 0.0013774104683195593, 'mean_word_length': 3.1813819577735125, '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': '721626', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1391, 'n_words': 262}