Skip to content

Commit

Permalink
only use IDB cursor for everything hack if creating the cursor errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
stutrek committed Jan 19, 2021
1 parent 811a1be commit 01ac9e9
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 10 deletions.
15 changes: 14 additions & 1 deletion dist/es/methods/indexed-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,21 @@ function getAllMessages(db) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];

function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}

return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;

if (cursor) {
Expand Down
15 changes: 14 additions & 1 deletion dist/lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,21 @@ function getAllMessages(db) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];

function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}

return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;

if (cursor) {
Expand Down
2 changes: 1 addition & 1 deletion dist/lib/browser.min.js

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion dist/lib/methods/indexed-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,21 @@ function getAllMessages(db) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];

function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}

return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;

if (cursor) {
Expand Down
15 changes: 14 additions & 1 deletion docs/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,21 @@ function getAllMessages(db) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];

function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}

return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;

if (cursor) {
Expand Down
15 changes: 14 additions & 1 deletion docs/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,21 @@ function getAllMessages(db) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];

function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}

return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;

if (cursor) {
Expand Down
15 changes: 14 additions & 1 deletion docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,21 @@ function getAllMessages(db) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];

function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}

return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;

if (cursor) {
Expand Down
15 changes: 14 additions & 1 deletion docs/leader-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,21 @@ function getAllMessages(db) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];

function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}

return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;

if (cursor) {
Expand Down
15 changes: 14 additions & 1 deletion docs/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,21 @@ function getAllMessages(db) {
function getMessagesHigherThan(db, lastCursorId) {
var objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
var ret = [];

function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}

return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;

if (cursor) {
Expand Down
15 changes: 14 additions & 1 deletion src/methods/indexed-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,21 @@ export function getAllMessages(db) {
export function getMessagesHigherThan(db, lastCursorId) {
const objectStore = db.transaction(OBJECT_STORE_ID).objectStore(OBJECT_STORE_ID);
const ret = [];

function openCursor() {
// Occasionally Safari will fail on IDBKeyRange.bound, this
// catches that error, having it open the cursor to the first
// item. When it gets data it will advance to the desired key.
try {
const keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (e) {
return objectStore.openCursor();
}
}

return new Promise(res => {
objectStore.openCursor().onsuccess = ev => {
openCursor().onsuccess = ev => {
const cursor = ev.target.result;
if (cursor) {
if (cursor.value.id < lastCursorId + 1) {
Expand Down

0 comments on commit 01ac9e9

Please sign in to comment.