Move to broadcast channel check for worker put asset
This commit is contained in:
parent
ab9cc9e148
commit
0bbfc4cdc3
@ -75,13 +75,18 @@ export function AssetsProvider({ children }) {
|
|||||||
|
|
||||||
const putAsset = useCallback(
|
const putAsset = useCallback(
|
||||||
async (asset) => {
|
async (asset) => {
|
||||||
// Attempt to use worker to put map to avoid UI lockup
|
// Check for broadcast channel and attempt to use worker to put map to avoid UI lockup
|
||||||
const packedAsset = encode(asset);
|
// Safari doesn't support BC so fallback to single thread
|
||||||
const success = await worker.putData(
|
if (window.BroadcastChannel) {
|
||||||
Comlink.transfer(packedAsset, [packedAsset.buffer]),
|
const packedAsset = encode(asset);
|
||||||
"assets"
|
const success = await worker.putData(
|
||||||
);
|
Comlink.transfer(packedAsset, [packedAsset.buffer]),
|
||||||
if (!success) {
|
"assets"
|
||||||
|
);
|
||||||
|
if (!success) {
|
||||||
|
await database.table("assets").put(asset);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
await database.table("assets").put(asset);
|
await database.table("assets").put(asset);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -75,9 +75,6 @@ export function groupBy(array, key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const isMacLike = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
|
export const isMacLike = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
|
||||||
export const isSafari = /^((?!chrome|android).)*safari/i.test(
|
|
||||||
navigator.userAgent
|
|
||||||
);
|
|
||||||
|
|
||||||
export function shuffle(array) {
|
export function shuffle(array) {
|
||||||
let temp = [...array];
|
let temp = [...array];
|
||||||
|
@ -8,7 +8,6 @@ import { encode, decode } from "@msgpack/msgpack";
|
|||||||
|
|
||||||
import { getDatabase } from "../database";
|
import { getDatabase } from "../database";
|
||||||
import blobToBuffer from "../helpers/blobToBuffer";
|
import blobToBuffer from "../helpers/blobToBuffer";
|
||||||
import { isSafari } from "../helpers/shared";
|
|
||||||
|
|
||||||
// Worker to load large amounts of database data on a separate thread
|
// Worker to load large amounts of database data on a separate thread
|
||||||
let service = {
|
let service = {
|
||||||
@ -46,10 +45,6 @@ let service = {
|
|||||||
* @param {string} table
|
* @param {string} table
|
||||||
*/
|
*/
|
||||||
async putData(data, table) {
|
async putData(data, table) {
|
||||||
if (isSafari) {
|
|
||||||
// Safari is unable to put data into indexedb and have useLiveQuery update
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
let db = getDatabase({});
|
let db = getDatabase({});
|
||||||
const decoded = decode(data);
|
const decoded = decode(data);
|
||||||
|
Loading…
Reference in New Issue
Block a user