Skip to content

(old) Remove User File Service Local Cache - #1476

Closed
ethanwong16 wants to merge 3 commits into
apache:masterfrom
ethanwong16:ethan-refactor-user-file
Closed

ethanwong16 wants to merge 3 commits into
apache:masterfrom
ethanwong16:ethan-refactor-user-file

Conversation

@ethanwong16

Copy link
Copy Markdown
Contributor

Introduction

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 self-assigned this Mar 11, 2022
@ethanwong16 ethanwong16 added refactor Refactor the code and removed refactor Refactor the code labels Mar 11, 2022
@Yicong-Huang Yicong-Huang added refactor Refactor the code fix labels Mar 16, 2022

@Yicong-Huang Yicong-Huang 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.

Left a comment. I want to test this PR however this seems from a forked repo. Can you create the branch in texera/Texera instead?

Comment on lines 166 to +175
private registerUpdateUserFileInFileSourceOp(): void {
this.userFileService.getUserFilesChangedEvent().subscribe(_ => {
this.userFileNames = this.userFileService.getUserFiles().map(file => `${file.ownerName}/${file.file.name}`);

Array.from(this.dynamicSchemaService.getDynamicSchemaMap().keys()).forEach(operatorID => {
const schema = this.dynamicSchemaService.getDynamicSchema(operatorID);
// if operator input attributes are in the result, set them in dynamic schema
const fileSchema = this.changeInputToEnumInJsonSchema(
schema,
fileNameInJsonSchema,
this.userFileNames,
"File Name"
);
if (!fileSchema) {
return;
}
if (!isEqual(schema, fileSchema)) {
SchemaPropagationService.resetAttributeOfOperator(this.workflowActionService, operatorID);
this.dynamicSchemaService.setDynamicSchema(operatorID, fileSchema);
}
this.userFileService
.getUserFilesChangedEvent()
.pipe(
concatMap(_ => {
return this.userFileService.retrieveDashboardUserFileEntryList();
})
)
.subscribe(dashboardFileEntries => {
this.userFileNames = dashboardFileEntries.map(file => `${file.ownerName}/${file.file.name}`);

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.

the source table service updates files whenever the user file changes. however, if user file does not change, how does it initialize the file list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

@ethanwong16

Copy link
Copy Markdown
Contributor Author

Left a comment. I want to test this PR however this seems from a forked repo. Can you create the branch in texera/Texera instead?

Just created the new branch on texera/Texera, should I continue to push any changes to this forked branch or would it be better to reopen the PR on the new branch?

@Yicong-Huang

Copy link
Copy Markdown
Contributor

Left a comment. I want to test this PR however this seems from a forked repo. Can you create the branch in texera/Texera instead?

Just created the new branch on texera/Texera, should I continue to push any changes to this forked branch or would it be better to reopen the PR on the new branch?

would be better to reopen with the branch in texera/Texera. thanks!

@ethanwong16 ethanwong16 changed the title Remove User File Service Local Cache (old) Remove User File Service Local Cache Mar 18, 2022
@ethanwong16

ethanwong16 commented Mar 18, 2022 •

Copy link
Copy Markdown
Contributor Author

reopened PR on new branch #1486

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.

2 participants