mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-19 17:41:38 +00:00
not sure we need the journal functionality + bug in idb found...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
737b250361
commit
11f801dddd
@ -19,6 +19,8 @@ var index = require('../index')
|
|||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
|
// XXX see bugs/issues...
|
||||||
|
// XXX not sure if we need this...
|
||||||
var JournalDB =
|
var JournalDB =
|
||||||
module.JournalDB =
|
module.JournalDB =
|
||||||
object.Constructor('JournalDB', {
|
object.Constructor('JournalDB', {
|
||||||
@ -57,13 +59,14 @@ object.Constructor('JournalDB', {
|
|||||||
switch(old){
|
switch(old){
|
||||||
// setup...
|
// setup...
|
||||||
case 0:
|
case 0:
|
||||||
console.log('CREATE!!')
|
console.log('JournalDB.db: create.')
|
||||||
var journal = db.createObjectStore('journal', {keyPath: 'date'})
|
var journal = db.createObjectStore('journal', {keyPath: 'date'})
|
||||||
journal.createIndex('path', 'path')
|
journal.createIndex('path', 'path')
|
||||||
// update...
|
// update...
|
||||||
case 1:
|
case 1:
|
||||||
// update code...
|
// update code...
|
||||||
} }
|
}
|
||||||
|
resolve(db) }
|
||||||
req.onversionchange = function(evt){
|
req.onversionchange = function(evt){
|
||||||
// XXX close connections and reload...
|
// XXX close connections and reload...
|
||||||
// ...this means that two+ versions of code opened the
|
// ...this means that two+ versions of code opened the
|
||||||
@ -135,6 +138,9 @@ object.Constructor('JournalDB', {
|
|||||||
.objectStore('journal')
|
.objectStore('journal')
|
||||||
.delete(IDBKeyRange.upperBound(to ?? 0, true))) },
|
.delete(IDBKeyRange.upperBound(to ?? 0, true))) },
|
||||||
// clear journal...
|
// clear journal...
|
||||||
|
// XXX BUG? for some reason .deleteDatabase(..) does not actually delete
|
||||||
|
// the database until a reload thus messing up the db creation
|
||||||
|
// process (as the .onversionchange event is not triggered)...
|
||||||
clear: function(){
|
clear: function(){
|
||||||
indexedDB.deleteDatabase(this.id)
|
indexedDB.deleteDatabase(this.id)
|
||||||
delete this.__db },
|
delete this.__db },
|
||||||
@ -566,12 +572,22 @@ module.BaseStore = {
|
|||||||
|
|
||||||
|
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
|
// XXX see issues with indexedDB...
|
||||||
|
// XXX not sure if we need this...
|
||||||
// XXX need a persistent fast store of changes...
|
// XXX need a persistent fast store of changes...
|
||||||
|
//__journal_id__: 'pWiki:test-journal',
|
||||||
|
__journal_db: undefined,
|
||||||
__journal: index.makeIndex('journal',
|
__journal: index.makeIndex('journal',
|
||||||
function(){
|
function(){
|
||||||
// XXX stub...
|
// XXX stub...
|
||||||
var data = []
|
var journal = this.__journal_db =
|
||||||
return data }, {
|
this.__journal_db
|
||||||
|
?? (this.__journal_id__ ?
|
||||||
|
JournalDB(this.__journal_id__)
|
||||||
|
: undefined)
|
||||||
|
return journal ?
|
||||||
|
journal.slice()
|
||||||
|
: [] }, {
|
||||||
|
|
||||||
'__call__': function(data, name, from, to){
|
'__call__': function(data, name, from, to){
|
||||||
if(typeof(from) == 'object'){
|
if(typeof(from) == 'object'){
|
||||||
@ -590,22 +606,37 @@ module.BaseStore = {
|
|||||||
// XXX do we need this???
|
// XXX do we need this???
|
||||||
'journal-clear': function(data, name){
|
'journal-clear': function(data, name){
|
||||||
this.__journal('clear')
|
this.__journal('clear')
|
||||||
|
this.__journal_db
|
||||||
|
&& this.__journal_db.clear()
|
||||||
return data },
|
return data },
|
||||||
|
|
||||||
// XXX these need to be persistent...
|
// XXX these need to be persistent...
|
||||||
update: function(data, name, path, update){
|
update: async function(data, name, path, update){
|
||||||
|
var date = this.__journal_db ?
|
||||||
|
this.__journal_db.add(path, 'update', update)
|
||||||
|
: Date.now()
|
||||||
|
data = await data
|
||||||
|
// XXX need to reuse the actual date...
|
||||||
data.push([Date.now(), 'update', path, update])
|
data.push([Date.now(), 'update', path, update])
|
||||||
return data },
|
return data },
|
||||||
remove: function(data, name, path){
|
remove: async function(data, name, path){
|
||||||
|
var date = this.__journal_db ?
|
||||||
|
this.__journal_db.add(path, 'update', update)
|
||||||
|
: Date.now()
|
||||||
|
data = await data
|
||||||
|
// XXX need to reuse the actual date...
|
||||||
data.push([Date.now(), 'remove', path])
|
data.push([Date.now(), 'remove', path])
|
||||||
return data },
|
return data },
|
||||||
|
|
||||||
save: function(data, name){
|
// XXX clear the .__journal_db...
|
||||||
|
save: async function(data, name){
|
||||||
|
data = await data
|
||||||
data.push([Date.now(), 'save'])
|
data.push([Date.now(), 'save'])
|
||||||
if(this.__cache_path__){
|
if(this.__cache_path__){
|
||||||
var path = this.__cache_path__ +'/'+ name+'_index'
|
var path = this.__cache_path__ +'/'+ name+'_index'
|
||||||
this.update(path, {index: data}) }
|
this.update(path, {index: data}) }
|
||||||
return data},
|
return data},
|
||||||
|
// XXX populate the .__journal_db???
|
||||||
load: async function(data, name){
|
load: async function(data, name){
|
||||||
// load...
|
// load...
|
||||||
if(this.__cache_path__){
|
if(this.__cache_path__){
|
||||||
@ -617,6 +648,7 @@ module.BaseStore = {
|
|||||||
&& this.delete(this.__cache_path__ +'/'+ name+'_index') }, }),
|
&& this.delete(this.__cache_path__ +'/'+ name+'_index') }, }),
|
||||||
journal: function(){
|
journal: function(){
|
||||||
return this.__journal('__call__', ...arguments)},
|
return this.__journal('__call__', ...arguments)},
|
||||||
|
//*/
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@ -36,6 +36,9 @@
|
|||||||
*
|
*
|
||||||
* XXX ASAP: do/test IndexedDB journal "live" store...
|
* XXX ASAP: do/test IndexedDB journal "live" store...
|
||||||
* XXX BUG: <store>.tags.tags seems to be broken -- no paths in sets...
|
* XXX BUG: <store>.tags.tags seems to be broken -- no paths in sets...
|
||||||
|
* XXX BUG: indexedDB: .deleteDatabase(..) does not actually delete the
|
||||||
|
* database from the list until reload.
|
||||||
|
* this breaks trying to open a database with the same name again...
|
||||||
* XXX FEATURE: would be nice to have a buffered store (mixin)...
|
* XXX FEATURE: would be nice to have a buffered store (mixin)...
|
||||||
* - state stored in memory
|
* - state stored in memory
|
||||||
* - get state from memory (sync)
|
* - get state from memory (sync)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user