Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Bryan Kaperick
jio
Commits
dc356c98
Commit
dc356c98
authored
Jun 05, 2018
by
Bryan Kaperick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replaced _revision counter with a _timestamp identifier which allows parallel put calls to work.
parent
30b0e964
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
95 deletions
+71
-95
src/jio.storage/bryanstorage.js
src/jio.storage/bryanstorage.js
+10
-47
test/jio.storage/bryanstorage.tests.js
test/jio.storage/bryanstorage.tests.js
+61
-48
No files found.
src/jio.storage/bryanstorage.js
View file @
dc356c98
...
...
@@ -25,58 +25,20 @@
};
BryanStorage
.
prototype
.
post
=
function
(
metadata
)
{
// Uses UuidStorage post
return
this
.
_sub_storage
.
post
(
metadata
);
};
BryanStorage
.
prototype
.
put
=
function
(
id
,
new_metadata
)
{
var
storage
=
this
,
substorage
=
this
.
_sub_storage
,
previous_data
;
BryanStorage
.
prototype
.
put
=
function
(
id
,
metadata
)
{
var
storage
=
this
;
return
this
.
_sub_storage
.
get
(
id
)
.
push
(
function
(
latest_data
)
{
// Prepare to post the current doc as a deprecated version
previous_data
=
latest_data
;
previous_data
.
_deprecated
=
"
true
"
;
previous_data
.
_doc_id
=
id
;
// Get most recent deprecated version's _revision attribute
var
options
=
{
query
:
'
(_doc_id: "
'
+
id
+
'
")
'
,
sort_on
:
[[
'
_revision
'
,
'
descending
'
]],
limit
:
[
0
,
1
]
};
//return substorage.buildQuery(options);
return
substorage
.
allDocs
(
options
);
})
.
push
(
function
(
query_results
)
{
if
(
query_results
.
data
.
rows
.
length
>
0
)
{
var
doc_id
=
query_results
.
data
.
rows
[
0
].
id
;
return
substorage
.
get
(
doc_id
);
}
throw
new
jIO
.
util
.
jIOError
(
"
bryanstorage: query returned no results.'
"
,
404
);
})
.
push
(
function
(
doc
)
{
previous_data
.
_revision
=
doc
.
_revision
+
1
;
return
storage
.
post
(
previous_data
);
},
function
()
{
// If the query turned up no results,
// there was exactly 1 version previously.
if
(
previous_data
!==
undefined
)
{
previous_data
.
_revision
=
0
;
return
storage
.
post
(
previous_data
);
}
})
// No matter what happened, need to put new document in
return
this
.
_sub_storage
.
put
(
id
,
metadata
)
.
push
(
function
()
{
return
substorage
.
put
(
id
,
new_metadata
);
// Also push a metadata document recording the posting time
metadata
.
_deprecated
=
"
true
"
;
metadata
.
_doc_id
=
id
;
metadata
.
_timestamp
=
Date
.
now
();
return
storage
.
post
(
metadata
);
});
};
...
...
@@ -151,6 +113,7 @@
if
(
options
.
query
!==
""
)
{
options
.
query
=
"
(
"
+
options
.
query
+
"
) AND
"
;
}
options
.
query
=
options
.
query
+
'
NOT (_deprecated: "true")
'
;
return
this
.
_sub_storage
.
buildQuery
(
options
);
};
...
...
test/jio.storage/bryanstorage.tests.js
View file @
dc356c98
...
...
@@ -11,72 +11,94 @@
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
;
/**
/////////////////////////////////////////////////////////////////
// _revision parameter updating with RSVP all
/////////////////////////////////////////////////////////////////
module("bryanStorage
_
revision with RSVP all");
test("verifying
_revision
updates correctly when puts are done in parallel",
module
(
"
bryanStorage revision with RSVP all
"
);
test
(
"
verifying updates correctly when puts are done in parallel
"
,
function
()
{
stop
();
expect(
1
);
expect
(
3
);
// create storage of type "bryan" with memory as substorage
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "uuid",
var
dbname
=
"
rsvp_db_
"
+
Date
.
now
(),
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type: "memory"
type
:
"
uuid
"
,
sub_storage
:
{
//type: "memory"
type
:
"
indexeddb
"
,
database
:
dbname
}
}
}
}),
}),
not_bryan
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type: "memory"
//type: "memory"
type
:
"
indexeddb
"
,
database
:
dbname
}
}
});
jio.put("bar", {"title": "foo0"});
RSVP.all([
jio.put("bar", {"title": "foo1"}),
jio.put("bar", {"title": "foo2"}),
jio.put("bar", {"title": "foo3"}),
jio.put("bar", {"title": "foo4"})
])
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo0
"
})
.
push
(
function
()
{
return
RSVP
.
all
([
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo1
"
}),
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo2
"
}),
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo3
"
}),
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo4
"
})
]);
})
.
push
(
function
()
{
return
jio
.
get
(
"
bar
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
foo4
"
});
})
.push(function () {return not_bryan.allDocs({
query: "_revision: 0"
});
})
.
push
(
function
()
{
return
not_bryan
.
allDocs
({
query
:
""
,
sort_on
:
[[
"
_timestamp
"
,
"
ascending
"
]]
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
1,
"Only one document with _revision = 0");
6
,
"
Storage contains all 5 revisions plus the most recent one.
"
);
return
not_bryan
.
get
(
results
.
data
.
rows
[
1
].
id
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
foo0
"
,
_doc_id
:
"
bar
"
,
_timestamp
:
result
.
_timestamp
,
_deprecated
:
"
true
"
},
"
Query returns the first edition of the document
"
);
})
.
fail
(
function
(
error
)
{
//console.log(error);
ok
(
false
,
error
);
})
.fail(function (error) {ok(false, error); })
.
always
(
function
()
{
start
();
});
});
**/
/////////////////////////////////////////////////////////////////
// bryanStorage revision history
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.revision_history
"
);
test
(
"
put and get the correct version
"
,
function
()
{
stop
();
expect
(
7
);
var
dbname
=
"
rev_hist_db
0
"
,
var
dbname
=
"
rev_hist_db
"
+
Date
.
now
()
,
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
...
...
@@ -102,12 +124,12 @@
query_input
=
{
query
:
'
NOT (_deprecated: "true")
'
,
sort_on
:
[[
'
_
revision
'
,
'
descending
'
]]
sort_on
:
[[
'
_
timestamp
'
,
'
descending
'
]]
},
query_input2
=
{
query
:
'
title: "rev1"
'
,
sort_on
:
[[
'
_
revision
'
,
'
descending
'
]]
sort_on
:
[[
'
_
timestamp
'
,
'
descending
'
]]
};
jio
.
put
(
"
doc1
"
,
{
...
...
@@ -164,7 +186,7 @@
"
title
"
:
"
rev1
"
,
"
subtitle
"
:
"
subrev1
"
,
"
_deprecated
"
:
"
true
"
,
"
_
revision
"
:
1
,
"
_
timestamp
"
:
result
.
_timestamp
,
"
_doc_id
"
:
"
doc1
"
},
"
Retrieve 1st edit by querying for title: 'rev1' with other storage
"
);
...
...
@@ -199,12 +221,11 @@
// bryanStorage.revision_history_multiple_edits
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.revision_history_multiple_edits
"
);
test
(
"
modify first version but save both
"
,
function
()
{
stop
();
expect
(
1
1
);
var
dbname
=
"
testdb20
"
,
expect
(
1
0
);
var
dbname
=
"
rev_hist_mult_db
"
+
Date
.
now
()
,
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
...
...
@@ -310,14 +331,6 @@
.
push
(
function
(
result
)
{
equal
(
result
.
data
.
rows
.
length
,
0
,
"
Correct number of results returned
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
'
(_revision: 0)
'
});
})
.
push
(
function
(
result
)
{
equal
(
result
.
data
.
rows
.
length
,
0
,
"
Correct number of results returned
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
''
...
...
@@ -331,14 +344,14 @@
.
push
(
function
()
{
var
options
=
{
query
:
"
_doc_id: main_doc
"
,
sort_on
:
[[
"
_
revision
"
,
"
ascending
"
]]
sort_on
:
[[
"
_
timestamp
"
,
"
ascending
"
]]
};
return
not_bryan
.
allDocs
(
options
);
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
3
,
"
should get all 3 deprecated versions.
"
);
4
,
"
should get all 3 deprecated versions
plus one copy of the latest
.
"
);
return
not_bryan
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
results
)
{
...
...
@@ -346,7 +359,7 @@
"
title
"
:
"
rev0
"
,
"
subtitle
"
:
"
subrev0
"
,
"
_doc_id
"
:
"
main_doc
"
,
"
_
revision
"
:
0
,
"
_
timestamp
"
:
results
.
_timestamp
,
"
_deprecated
"
:
"
true
"
},
"
Get the earliest copy of the doc with all metadata.
"
);
...
...
@@ -356,7 +369,7 @@
.
push
(
function
()
{
var
options
=
{
query
:
"
_doc_id: main_doc
"
,
sort_on
:
[[
"
_
revision
"
,
"
ascending
"
]]
sort_on
:
[[
"
_
timestamp
"
,
"
ascending
"
]]
};
return
not_bryan
.
allDocs
(
options
);
})
...
...
@@ -368,7 +381,7 @@
"
title
"
:
"
rev1
"
,
"
subtitle
"
:
"
subrev1
"
,
"
_doc_id
"
:
"
main_doc
"
,
"
_
revision
"
:
1
,
"
_
timestamp
"
:
results
.
_timestamp
,
"
_deprecated
"
:
"
true
"
},
"
Get the earliest copy of the doc with all metadata.
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment