Explorar o código

cache invalidation before map rendering

Viktoriia hai 1 semana
pai
achega
dd997c7e28
Modificáronse 3 ficheiros con 14 adicións e 18 borrados
  1. 3 2
      Route.tsx
  2. 10 2
      src/database/index.ts
  3. 1 14
      src/database/tilesService/index.ts

+ 3 - 2
Route.tsx

@@ -58,7 +58,7 @@ import { openDatabases } from './src/db';
 
 import TabBarButton from './src/components/TabBarButton';
 import { ParamListBase, RouteProp, useIsFocused } from '@react-navigation/native';
-import setupDatabaseAndSync, { initializeDatabase } from 'src/database';
+import setupDatabaseAndSync, { initializeDatabase, invalidateMapCache } from 'src/database';
 import { MenuDrawer } from 'src/components';
 import { API_URL, APP_VERSION } from 'src/constants';
 import {
@@ -220,6 +220,7 @@ const Route = () => {
       // await checkTokenAndUpdate();
       await openDatabases();
       setDbLoaded(true);
+      await invalidateMapCache();
       updateNotificationStatus();
       updateUnreadMessagesCount();
       if (uid && token) {
@@ -244,8 +245,8 @@ const Route = () => {
     const hideSplashScreen = async () => {
       if (fontsLoaded) {
         await SplashScreen.hideAsync();
-        await fetchAndSaveUserInfo();
         await setupDatabaseAndSync();
+        await fetchAndSaveUserInfo();
       }
     };
 

+ 10 - 2
src/database/index.ts

@@ -1,7 +1,7 @@
 import NetInfo, { NetInfoState } from '@react-native-community/netinfo';
 import { StoreType, storage } from 'src/storage';
 import { fetchLpi, fetchInHistory, fetchInMemoriam, updateMaster } from '@api/ranking';
-import { initOfflineSetup } from './tilesService';
+import { initOfflineSetup, updateMapsCache } from './tilesService';
 import { downloadFlags } from './flagsService';
 import { fetchAndSaveAllTypesAndMasters } from './unMastersService';
 import { fetchAndSaveStatistics } from './statisticsService';
@@ -32,7 +32,15 @@ export const syncDataWithServer = async (): Promise<void> => {
     await updateDarePlacesDb(lastUpdateDarePlaces);
     await initOfflineSetup();
     await updateMasterRanking();
-    await downloadFlags();
+    // await downloadFlags();
+  }
+};
+
+export const invalidateMapCache = async () => {
+  const { isConnected } = await checkInternetConnection();
+
+  if (isConnected) {
+    await updateMapsCache();
   }
 };
 

+ 1 - 14
src/database/tilesService/index.ts

@@ -5,21 +5,9 @@ import { VECTOR_MAP_HOST } from 'src/constants';
 import { fetchLastMapTilesUpdate } from '@api/app';
 import { storage, StoreType } from 'src/storage';
 
-const baseTilesDir = `${FileSystem.cacheDirectory}tiles/`;
 const STYLE_URL = `${VECTOR_MAP_HOST}/nomadmania-maps2025.json`;
 const PACK_NAME = 'vector-map-pack';
 
-async function deleteCachedTilesIfExist(): Promise<void> {
-  try {
-    const dirInfo = await FileSystem.getInfoAsync(baseTilesDir, { size: true });
-    if (dirInfo.exists) {
-      await FileSystem.deleteAsync(baseTilesDir, { idempotent: true });
-    }
-  } catch (error) {
-    console.error('Error deleting cached tiles:', error);
-  }
-}
-
 function getPackName(p: any): string | undefined {
   if (p?.name) return p.name;
 
@@ -73,8 +61,7 @@ async function setupOfflineRegion(): Promise<void> {
 }
 
 export async function initOfflineSetup(): Promise<void> {
-  await deleteCachedTilesIfExist();
-  await updateMapsCache();
+  // await updateMapsCache();
   await setupOfflineRegion();
 }