Skip to content

Commit

Permalink
Remove normalised cache (#2390)
Browse files Browse the repository at this point in the history
* yeetus

* fix

* a

* fix

* todo

* fix library stuff

---------

Co-authored-by: Jamie Pine <[email protected]>
  • Loading branch information
oscartbeaumont and jamiepine authored Apr 30, 2024
1 parent c76320e commit ce5e285
Show file tree
Hide file tree
Showing 74 changed files with 279 additions and 1,397 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node-linker=hoisted
auto-install-peers=true
max-old-space-size=4096
enable-pre-post-scripts=true
package-manager-strict=false
12 changes: 0 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryClientProvider } from '@tanstack/react-query';
import { listen } from '@tauri-apps/api/event';
import { PropsWithChildren, startTransition, useEffect, useMemo, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { CacheProvider, createCache, RspcProvider } from '@sd/client';
import { RspcProvider } from '@sd/client';
import {
createRoutes,
ErrorPage,
Expand Down Expand Up @@ -56,16 +56,14 @@ export default function App() {
return (
<RspcProvider queryClient={queryClient}>
<QueryClientProvider client={queryClient}>
<CacheProvider cache={cache}>
{startupError ? (
<ErrorPage
message={startupError}
submessage="Error occurred starting up the Spacedrive core"
/>
) : (
<AppInner />
)}
</CacheProvider>
{startupError ? (
<ErrorPage
message={startupError}
submessage="Error occurred starting up the Spacedrive core"
/>
) : (
<AppInner />
)}
</QueryClientProvider>
</RspcProvider>
);
Expand All @@ -74,9 +72,7 @@ export default function App() {
// we have a minimum delay between creating new tabs as react router can't handle creating tabs super fast
const TAB_CREATE_DELAY = 150;

const cache = createCache();

const routes = createRoutes(platform, cache);
const routes = createRoutes(platform);

type redirect = { pathname: string; search: string | undefined };

Expand Down
7 changes: 1 addition & 6 deletions apps/mobile/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import { MenuProvider } from 'react-native-popup-menu';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { useSnapshot } from 'valtio';
import {
CacheProvider,
ClientContextProvider,
createCache,
initPlausible,
LibraryContextProvider,
P2PContextProvider,
Expand Down Expand Up @@ -146,7 +144,6 @@ function AppContainer() {
}

const queryClient = new QueryClient();
const cache = createCache();

export default function App() {
useEffect(() => {
Expand All @@ -155,9 +152,7 @@ export default function App() {

return (
<RspcProvider queryClient={queryClient}>
<CacheProvider cache={cache}>
<AppContainer />
</CacheProvider>
<AppContainer />
</RspcProvider>
);
}
5 changes: 2 additions & 3 deletions apps/mobile/src/components/browse/BrowseLocations.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useNavigation } from '@react-navigation/native';
import { useCache, useLibraryQuery, useNodes } from '@sd/client';
import { DotsThreeOutline, Plus } from 'phosphor-react-native';
import { useRef } from 'react';
import { Text, View } from 'react-native';
import { useLibraryQuery } from '@sd/client';
import { ModalRef } from '~/components/layout/Modal';
import { tw } from '~/lib/tailwind';
import { BrowseStackScreenProps } from '~/navigation/tabs/BrowseStack';
Expand All @@ -22,8 +22,7 @@ const BrowseLocations = () => {
const modalRef = useRef<ModalRef>(null);

const result = useLibraryQuery(['locations.list'], { keepPreviousData: true });
useNodes(result.data?.nodes);
const locations = useCache(result.data?.items);
const locations = result.data;

return (
<View style={tw`gap-5 px-6`}>
Expand Down
6 changes: 2 additions & 4 deletions apps/mobile/src/components/browse/BrowseTags.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useNavigation } from '@react-navigation/native';
import { useCache, useLibraryQuery, useNodes } from '@sd/client';
import { DotsThreeOutline, Plus } from 'phosphor-react-native';
import React, { useRef } from 'react';
import { Text, View } from 'react-native';
import { useLibraryQuery } from '@sd/client';
import { ModalRef } from '~/components/layout/Modal';
import { tw } from '~/lib/tailwind';
import { BrowseStackScreenProps } from '~/navigation/tabs/BrowseStack';
Expand All @@ -16,9 +16,7 @@ const BrowseTags = () => {
const navigation = useNavigation<BrowseStackScreenProps<'Browse'>['navigation']>();

const tags = useLibraryQuery(['tags.list']);

useNodes(tags.data?.nodes);
const tagData = useCache(tags.data?.items);
const tagData = tags.data;

const modalRef = useRef<ModalRef>(null);

Expand Down
11 changes: 2 additions & 9 deletions apps/mobile/src/components/context/OnboardingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
useBridgeMutation,
useCachedLibraries,
useMultiZodForm,
useNormalisedCache,
useOnboardingStore,
usePlausibleEvent
} from '@sd/client';
Expand Down Expand Up @@ -69,12 +68,8 @@ const useFormState = () => {
const submitPlausibleEvent = usePlausibleEvent();

const queryClient = useQueryClient();
const cache = useNormalisedCache();
const createLibrary = useBridgeMutation('library.create', {
onSuccess: (libRaw) => {
cache.withNodes(libRaw.nodes);
const lib = cache.withCache(libRaw.item);

onSuccess: (lib) => {
// We do this instead of invalidating the query because it triggers a full app re-render??
insertLibrary(queryClient, lib);
}
Expand All @@ -90,15 +85,13 @@ const useFormState = () => {

try {
// show creation screen for a bit for smoothness
const [libraryRaw] = await Promise.all([
const [library] = await Promise.all([
createLibrary.mutateAsync({
name: data.NewLibrary.name,
default_locations: null
}),
new Promise((res) => setTimeout(res, 500))
]);
cache.withNodes(libraryRaw.nodes);
const library = cache.withCache(libraryRaw.item);

if (telemetryState.shareFullTelemetry) {
submitPlausibleEvent({ event: { type: 'libraryCreate' } });
Expand Down
13 changes: 2 additions & 11 deletions apps/mobile/src/components/drawer/DrawerLocations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ import { DrawerNavigationHelpers } from '@react-navigation/drawer/lib/typescript
import { useNavigation } from '@react-navigation/native';
import { useRef } from 'react';
import { Pressable, Text, View } from 'react-native';
import {
arraysEqual,
byteSize,
Location,
useCache,
useLibraryQuery,
useNodes,
useOnlineLocations
} from '@sd/client';
import { arraysEqual, byteSize, Location, useLibraryQuery, useOnlineLocations } from '@sd/client';
import { ModalRef } from '~/components/layout/Modal';
import { tw, twStyle } from '~/lib/tailwind';

Expand Down Expand Up @@ -67,8 +59,7 @@ const DrawerLocations = () => {
const modalRef = useRef<ModalRef>(null);

const result = useLibraryQuery(['locations.list'], { keepPreviousData: true });
useNodes(result.data?.nodes);
const locations = useCache(result.data?.items);
const locations = result.data || [];

return (
<>
Expand Down
5 changes: 2 additions & 3 deletions apps/mobile/src/components/drawer/DrawerTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DrawerNavigationHelpers } from '@react-navigation/drawer/lib/typescript
import { useNavigation } from '@react-navigation/native';
import { useRef } from 'react';
import { ColorValue, Pressable, Text, View } from 'react-native';
import { Tag, useCache, useLibraryQuery, useNodes } from '@sd/client';
import { Tag, useLibraryQuery } from '@sd/client';
import { ModalRef } from '~/components/layout/Modal';
import { tw, twStyle } from '~/lib/tailwind';

Expand Down Expand Up @@ -38,8 +38,7 @@ const DrawerTags = () => {
const tags = useLibraryQuery(['tags.list']);
const navigation = useNavigation<DrawerNavigationHelpers>();

useNodes(tags.data?.nodes);
const tagData = useCache(tags.data?.items);
const tagData = tags.data || [];

const modalRef = useRef<ModalRef>(null);

Expand Down
7 changes: 2 additions & 5 deletions apps/mobile/src/components/explorer/sections/InfoTagPills.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {
getItemFilePath,
getItemObject,
isPath,
useCache,
useLibraryQuery,
useNodes
useLibraryQuery
} from '@sd/client';
import { InfoPill, PlaceholderPill } from '~/components/primitive/InfoPill';
import { tw, twStyle } from '~/lib/tailwind';
Expand All @@ -25,8 +23,7 @@ const InfoTagPills = ({ data, style }: Props) => {
const tagsQuery = useLibraryQuery(['tags.getForObject', objectData?.id ?? -1], {
enabled: objectData != null
});
useNodes(tagsQuery.data?.nodes);
const items = useCache(tagsQuery.data?.items);
const items = tagsQuery.data;

const isDir = data && isPath(data) ? data.item.is_dir : false;

Expand Down
13 changes: 2 additions & 11 deletions apps/mobile/src/components/modal/CreateLibraryModal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { useQueryClient } from '@tanstack/react-query';
import { forwardRef, useState } from 'react';
import { Text, View } from 'react-native';
import {
insertLibrary,
useBridgeMutation,
useNormalisedCache,
usePlausibleEvent
} from '@sd/client';
import { insertLibrary, useBridgeMutation, usePlausibleEvent } from '@sd/client';
import { Modal, ModalRef } from '~/components/layout/Modal';
import { Button } from '~/components/primitive/Button';
import { ModalInput } from '~/components/primitive/Input';
Expand All @@ -18,18 +13,14 @@ const CreateLibraryModal = forwardRef<ModalRef, unknown>((_, ref) => {
const modalRef = useForwardedRef(ref);

const queryClient = useQueryClient();
const cache = useNormalisedCache();
const [libName, setLibName] = useState('');

const submitPlausibleEvent = usePlausibleEvent();

const { mutate: createLibrary, isLoading: createLibLoading } = useBridgeMutation(
'library.create',
{
onSuccess: (libRaw) => {
cache.withNodes(libRaw.nodes);
const lib = cache.withCache(libRaw.item);

onSuccess: (lib) => {
// Reset form
setLibName('');

Expand Down
Loading

0 comments on commit ce5e285

Please sign in to comment.