Skip to content

Remove User File Service Local Cache - #1486

Merged
ethanwong16 merged 13 commits into
masterfrom
ethan-refactor-user-file
Jun 1, 2022
Merged

ethanwong16 merged 13 commits into
masterfrom
ethan-refactor-user-file

Conversation

@ethanwong16

Copy link
Copy Markdown
Contributor

Introduction

Reopened PR of #1476

This PR refactors the code in the UserFileService to remove its local cache of DashboardUserFileEntries. It also updates all components depending on or using the UserFileService. The goal is to reduce usage of local caches within the user dashboard as well as simplify reuse of the UserFIleSectionComponent in the UserProjectSectionComponent.

Solution

Previously the UserFileService maintained a local cache of DashboardUserFileEntries and required components to invoke a function to continuously refresh this local cache. This also required components to continuously retrieve files from the UserFileService in case the cache might have changed. As a solution, the UserFIleService no longer keeps a local cache of DashboardUserFileEntries and now has a public function to retrieve DashboardUserFileEntries from a backend endpoint.

Detailed List of Changes Made

Changes were made only to the frontend.

  • user-file-service.ts

    • Removed local cache of DashboardUserFileEntry objects
      • Removed getUserFiles() function to access local cache
      • Removed detectUserChanges() function, similar logic is pushed up to UserFileSection
      • Removed refreshDashboardUserFileEntries() function, pushed up into UserFileSection
      • Changed deleteDashboardUserFileEntry() to return empty Observable to indicate when backend is finished, UserFileSection subscribes to it
      • Remove clearDashboardUserFileEntries() function, pushed up into UserFileSection
    • Changed retrieveDashboardUserFileEntryList() to be public, instead of maintaining a cache just retrieve from backend
    • Added updateUserFilesChangedEvent() function to allow for changing dashboardUserFileEntryChanged from UserFileSection; source-tables subscribes to this
  • stub-user-file.service.ts

    • Modified deleteDashboardUserFileEntry() stub since it now returns an Observable
    • Added retrieveDashbaordUserFileEntryList() stub because it is now public
    • Added updateUserFilesChangedEvent() stub
  • source-tables.service.ts

    • Removed usage of refreshDashboardUserFileEntries, no more local cache in UserFileService
    • Changed registerUpdateUserFileInSourceOp() to use concatMap, since an extra subscribe method to retrieve DashboardUserFileEntries is now needed (due to removal of cache, have to retrieve from backend)
  • user-file-section.component.ts

    • Added local cache to store ReadOnly dashboardUserFileEntries
      • Replace references to service’s cache with this local cache, removed getUserFiles() function
    • Add logic in registerDashboardFileEntriesRefresh() function to update file entries upon a user change, including log in / log out
    • Add refresh logic to retrieve DashboardUserFIleEntries from backend within ngOnInit()
      • Replace references of UserFileService’s refresh with this refresh
    • Add clear DashboardUserFileEntries logic
    • Modified process to openFileAddComponent modal, after modal is dismissed also update DashboardFileEntries
    • Modify deleteUserFileEntry() to refresh local cache after backend is finished
    • (Minor) Replaced usages of alert with NotificationService
    • (Minor) Replaced deprecated usages of RxJS subscribe() having multiple arguments, now only use one observer argument
  • user-file-upload.service.ts

    • Remove usage of UserFileService’s refresh function (no more service local cache)
    • (Minor) Replaced deprecated usages of RxJS subscribe() having multiple arguments, now only use one observer argument
  • user-project-section.component.ts

    • Removed usage of service’s refresh function (no more service local cache)
  • ngbd-modal-add-project-file.component.html

    • Update to use retrieved files from backend instead instead of continuously calling getUserFiles()
  • ngbd-modal-add-project-file.component.ts

    • Added temporary local variable for files that may be added
    • refactored code to use this local variable instead (similar to structure of add workflow modal)
  • user-project.service.ts

    • Remove usage of file service’s refresh (no more file service cache)

Future TODOs

  • Use newly refactored UserFileService to modify / reuse UserFileSection component within UserProjectSection

Updated Files:
- user-file-service.ts
- stub-user-file.service.ts
- source-tables.service.ts
- user-file-section.component.ts
- user-file-upload.service.ts
- user-project-section.component.ts
- ngbd-modal-add-project-file.component.html
- ngbd-modal-add-project-file.component.ts
- user-project.service.ts
@ethanwong16 ethanwong16 added fix refactor Refactor the code labels Mar 18, 2022
@ethanwong16

Copy link
Copy Markdown
Contributor Author

Previous Discussion

Screen Shot 2022-03-17 at 22 09 31


The current workaround I have is the updateUserFilesChangedEvent() function I added to the UserFileService. This function can be invoked to let the UserFileService know about a user file change so it can update dashboardUserFileEntryChanged.

In the original UserFileService, it would indicate a user file changed upon a refresh / clear of the files. So I updated the UserFileSection to invoke updateUserFilesChangedEvent() to inform the UserFileService whenever files would be refreshed or cleared.

Would this be a good way to handle the source table service updating files?

@Xiao-zhen-Liu

Copy link
Copy Markdown
Contributor

Discussion 2022.05.12: @zuozhiw will review this PR.

@zuozhiw zuozhiw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I've made some minor changes

@ethanwong16
ethanwong16 merged commit f390123 into master Jun 1, 2022
@ethanwong16
ethanwong16 deleted the ethan-refactor-user-file branch June 1, 2022 07:01
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
* Remove UserFileService local cache + update dependent references

Updated Files:
- user-file-service.ts
- stub-user-file.service.ts
- source-tables.service.ts
- user-file-section.component.ts
- user-file-upload.service.ts
- user-project-section.component.ts
- ngbd-modal-add-project-file.component.html
- ngbd-modal-add-project-file.component.ts
- user-project.service.ts

* Reformat files + make compatible with new frontend libraries

* Reverted notificationService change, not relevant to current PRs

* minor changes

* minor

* format

* revert

Co-authored-by: zuozhiw <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix refactor Refactor the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants