Use new module API
This commit is contained in:
@@ -18,6 +18,20 @@ export default class StorageService extends Service {
|
||||
});
|
||||
|
||||
this.rs.access.claim('places', 'rw');
|
||||
// Caching strategy:
|
||||
// With the new nested structure, enabling caching on root '/' might try to sync everything.
|
||||
// For now, let's keep it, but we might need to be more selective later if data grows huge.
|
||||
// Note: The path structure changed from /places/ to just root access in the module?
|
||||
// In places.ts: getPath returns "ab/cd/id".
|
||||
// RemoteStorage modules usually implicitly use a base scope based on module name if not defined differently?
|
||||
// Wait, the module defines `privateClient`.
|
||||
// When we do `privateClient.storeObject`, it stores it under the module's scope.
|
||||
// If module name is 'places', then it's stored under /places/.
|
||||
// So getPath "ab/cd/id" becomes "/places/ab/cd/id".
|
||||
// So enabling caching on '/places/' is correct.
|
||||
// However, per instructions, we should set maxAge to false for listings in the module,
|
||||
// which we did.
|
||||
// We also need to be careful about what we cache here.
|
||||
this.rs.caching.enable('/places/');
|
||||
|
||||
window.remoteStorage = this.rs;
|
||||
@@ -43,13 +57,30 @@ export default class StorageService extends Service {
|
||||
this.loadAllPlaces();
|
||||
}
|
||||
|
||||
async loadAllPlaces() {
|
||||
async loadAllPlaces(prefixes = null) {
|
||||
try {
|
||||
const places = await this.rs.places.listAll();
|
||||
// If prefixes is null, it loads everything (recursive scan).
|
||||
// If prefixes is an array ['w1q7'], it loads just that sector.
|
||||
const places = await this.rs.places.getPlaces(prefixes);
|
||||
|
||||
if (places && Array.isArray(places)) {
|
||||
this.savedPlaces = places;
|
||||
if (prefixes) {
|
||||
// If partial load, we might want to merge instead of replace?
|
||||
// For now, let's keep the simple behavior: replacing the tracked array triggers updates.
|
||||
// However, replacing 'all saved places' with 'just these visible places'
|
||||
// might hide other bookmarks from the list.
|
||||
|
||||
// Strategy: maintain a Map of loaded places to avoid duplicates/overwrites?
|
||||
// Or just append unique ones?
|
||||
const currentIds = new Set(this.savedPlaces.map((p) => p.id));
|
||||
const newPlaces = places.filter((p) => !currentIds.has(p.id));
|
||||
this.savedPlaces = [...this.savedPlaces, ...newPlaces];
|
||||
} else {
|
||||
// Full reload
|
||||
this.savedPlaces = places;
|
||||
}
|
||||
} else {
|
||||
this.savedPlaces = [];
|
||||
if (!prefixes) this.savedPlaces = [];
|
||||
}
|
||||
console.log('Loaded saved places:', this.savedPlaces.length);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user