Skip to content

Commit

Permalink
wip: increase powersync connection speed
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Jan 29, 2025
1 parent ef2a6c0 commit b4626d8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions packages/frontend/src/db/Connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export class Connector implements PowerSyncBackendConnector {
console.log("fetching credentials");
const token = await getTokenOrRefresh();

console.log("aaaa");

return {
endpoint: ENV.VITE_POWERSYNC_URL,
token,
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/src/db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const isFirefox = browser.getBrowser().name === "Firefox";
export const powerSyncDb = new PowerSyncDatabase({
schema: AppSchema,
flags: {
useWebWorker: !isFirefox,
useWebWorker: false && !isFirefox,
},
database: {
dbFilename: "crvif-sync.db",
Expand All @@ -22,7 +22,6 @@ export const db = wrapPowerSyncWithKysely<Database>(powerSyncDb);
export const useDbQuery = useQuery;

export const setupPowersync = async () => {
console.log("setup");
const connector = new Connector();
await powerSyncDb.init();
await powerSyncDb.connect(connector, {
Expand Down
11 changes: 8 additions & 3 deletions packages/frontend/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { startReactDsfr } from "@codegouvfr/react-dsfr/spa";
import React, { PropsWithChildren, useEffect, useMemo } from "react";
import React, { PropsWithChildren, useEffect, useMemo, useRef } from "react";
import ReactDOM from "react-dom/client";
import { App } from "./App";
import { AuthProvider, useAuthContext } from "./contexts/AuthContext";
Expand Down Expand Up @@ -33,9 +33,14 @@ const queryClient = new QueryClient({
},
});

setupPowersync();

const WithPowersync = ({ children }: PropsWithChildren) => {
const initRef = useRef(false);
useEffect(() => {
if (initRef.current) return;
setupPowersync();
initRef.current = true;
}, []);

return <PowerSyncContext.Provider value={powerSyncDb}>{children}</PowerSyncContext.Provider>;
};

Expand Down
1 change: 1 addition & 0 deletions packages/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default defineConfig({
manifestFilename: "manifest.webmanifest",
injectManifest: {
maximumFileSizeToCacheInBytes: 2097152 * 3,
// globPatterns: ["**/*.{svg,woff2,js,wasm,css,html,png}"],
globPatterns: ["**/*.{svg,woff2,js,wasm,css,html,png}"],
rollupFormat: "es",
},
Expand Down

0 comments on commit b4626d8

Please sign in to comment.