Skip to content

Commit

Permalink
add implement deleteCachedRecordsFromIds for SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
LocalNewsTV committed Jan 2, 2025
1 parent 7e1e340 commit fe0de66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/utils/record-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abstract class RecordCacheService {
abstract saveActivity(id: string, data: unknown): Promise<void>;

abstract saveIapp(id: string, iappRecord: unknown, iappTableRow: unknown): Promise<void>;

abstract deleteCachedRecordsFromIds(idsToDelete: string[], recordSetType: RecordSetType): Promise<void>;
abstract loadActivity(id: string): Promise<unknown>;
abstract loadIapp(id: string, type: IappRecordMode): Promise<IappRecord | IappTableRow>;

Expand Down
3 changes: 2 additions & 1 deletion app/src/utils/record-cache/localforage-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Feature } from '@turf/helpers';
import { GeoJSONSourceSpecification } from 'maplibre-gl';
import IappRecord from 'interfaces/IappRecord';
import IappTableRow from 'interfaces/IappTableRecord';
import { RecordSetType } from 'interfaces/UserRecordSet';

class LocalForageRecordCacheService extends RecordCacheService {
private static _instance: LocalForageRecordCacheService;
Expand Down Expand Up @@ -168,7 +169,7 @@ class LocalForageRecordCacheService extends RecordCacheService {
return { cachedCentroid, cachedGeoJson };
}

async deleteCachedRecordsFromIds(idsToDelete: string[]): Promise<void> {
async deleteCachedRecordsFromIds(idsToDelete: string[], recordSetType: RecordSetType): Promise<void> {
if (this.store == null) {
throw new Error('cache not available');
}
Expand Down
18 changes: 17 additions & 1 deletion app/src/utils/record-cache/sqlite-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Feature } from '@turf/helpers';
import IappRecord from 'interfaces/IappRecord';
import IappTableRow from 'interfaces/IappTableRecord';
import UserRecord from 'interfaces/UserRecord';
import { RecordSetType } from 'interfaces/UserRecordSet';
import { GeoJSONSourceSpecification } from 'maplibre-gl';
import { IappRecordMode, RecordCacheService, RecordSetSourceMetadata } from 'utils/record-cache/index';
import { sqlite } from 'utils/sharedSQLiteInstance';
Expand Down Expand Up @@ -282,7 +283,22 @@ class SQLiteRecordCacheService extends RecordCacheService {
};
return { cachedCentroid, cachedGeoJson };
}

async deleteCachedRecordsFromIds(idsToDelete: string[], recordSetType: RecordSetType): Promise<void> {
if (this.cacheDB == null) {
throw new Error(CACHE_UNAVAILABLE);
}
const RecordsToTable = {
[RecordSetType.Activity]: 'CACHED_RECORDS',
[RecordSetType.IAPP]: 'CACHED_IAPP_RECORDS'
};
const RECORD_TABLE = RecordsToTable[recordSetType];
await this.cacheDB.query(
// language=SQLite
`DELETE FROM ${RECORD_TABLE}
WHERE ID IN (${idsToDelete.map(() => '?').join(', ')})`,
[...idsToDelete]
);
}
private async initializeRecordCache(sqlite: SQLiteConnection) {
// Hold Migrations as named variable so we can use length to update the Db version automagically
// Note: toVersion must be an integer.
Expand Down

0 comments on commit fe0de66

Please sign in to comment.