Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IndexedDB property file caching #32

Open
2 tasks done
atefMck opened this issue Jun 7, 2024 · 0 comments
Open
2 tasks done

Add IndexedDB property file caching #32

atefMck opened this issue Jun 7, 2024 · 0 comments
Labels
feature Something new that we could do

Comments

@atefMck
Copy link

atefMck commented Jun 7, 2024

Description 📝

The viewer becomes data-intensive due to the repeated requests for property files, which are not cached and must be retrieved anew each time properties need to be accessed.

Suggested solution 💡

In the FragmentsGroup class, which contains the getProperties method that appears to be the primary function for retrieving properties, we could implement a caching system same as the one used for geometries.

Alternative ⛕

import Dexie from "dexie";

interface IStreamedFile {
  id: string;
  file: JSON;
}

export class StreamFileDatabase extends Dexie {
  // Declare implicit table properties.
  // (just to inform Typescript. Instantiated by Dexie in stores() method)
  files!: Dexie.Table<IStreamedFile, string>; // number = type of the primkey

  constructor() {
    super("MyAppDatabase");
    this.version(1).stores({
      files: "id, file",
    });
  }
}

export class FragmentsGroup extends THREE.Group {

private _fileCache = new StreamFileDatabase();

private async getPropertiesData(url: string) {
    const found = await this._fileCache.files.get(url);
    if (found) {
      return found.file;
    } else {
      const fetched = await fetch(url);
      const fileData = await fetched.json();
      this._fileCache.files.add({ id: url, file: fileData.data });
      return fileData && fileData.data ? fileData.data : null;
    }
  }

Additional context ☝️

No response

Validations ✅

  • Read the docs.
  • Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.
@atefMck atefMck added the feature Something new that we could do label Jun 7, 2024
@atefMck atefMck changed the title [Feat] Added IndexedDB property file caching Add IndexedDB property file caching Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Something new that we could do
Projects
None yet
Development

No branches or pull requests

1 participant