Skip to content

Add UserDictionaryService (User Presets Step 2) - #1162

Merged
zuozhiw merged 16 commits into
masterfrom
Albert-UserDictionaryService
Jun 27, 2021
Merged

zuozhiw merged 16 commits into
masterfrom
Albert-UserDictionaryService

Conversation

@MysteriousChallenger

@MysteriousChallenger MysteriousChallenger commented Jun 10, 2021 •

Copy link
Copy Markdown
Contributor

This PR is extracted from #1041 as step 2 of the User Preset feature.

rebase of picked commits pertaining to UserDictionaryService onto Albert-UserDictionaryResource

UserDictionaryService provides a "dictionary", a persistent collection of string (key, value) pairs for clients that are logged in
Changes from last review (for Yicong)

  • Much more code comments
  • using new API from User Presets Step 1
  • Get/Set/Delete methods return Observables instead of Promises now
  • Code should be much more readable because error handling and validation are separated into individual function definitions

adds user_dictionary database table and JOOQ generated DAOs and POJOs
user_dictionary stores uid+key -> json-value pairs, storing arbitrary json data for each user
fixed sql formatting, capitalized error messages, fixed edge case of missing json properties in requests
turns out XHR doesn't allow get requests to have a body, despite generating content-type/length headers and it being allowed in the inspector.
the dictionary service provides the frontend with observable event streams and w/r functions for the user dictionary resource.

It also provides userDictionary objects that are proxies to the user dictionary resource:
- get operations yield values from the user dictionary resource,
- set operations post values to the user dictionary resource
refactored to use new backend api. Get/Set/Delete operations now return Observables instead of Promises.
# Conflicts:
#	core/amber/src/main/scala/edu/uci/ics/texera/web/model/jooq/generated/Keys.java
#	core/amber/src/main/scala/edu/uci/ics/texera/web/model/jooq/generated/tables/User.java
#	core/amber/src/main/scala/edu/uci/ics/texera/web/model/jooq/generated/tables/UserDictionary.java
#	core/amber/src/main/scala/edu/uci/ics/texera/web/model/jooq/generated/tables/pojos/User.java
#	core/amber/src/main/scala/edu/uci/ics/texera/web/model/jooq/generated/tables/records/UserRecord.java
#	core/amber/src/main/scala/edu/uci/ics/texera/web/resource/UserDictionaryResource.scala
#	core/scripts/sql/texera_ddl.sql

@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 some comments to resolve. On the high level, I see there is a user-dictionary.service and now your service name is in conflict with that service. How can we resolve the conflict?
The feature is called User Presets but this name is not reflected in the code for now (it named user dictionary in code).

Comment on lines +191 to +198
const result = this.http.post<UserDictionaryResponse>(url, request)
.pipe(
map(this.handleEntryResponse.bind(this, key)),
catchError(DictionaryService.handleErrorResponse),
shareReplay());

result.subscribe(); // causes post request to actually be sent (see cold observables)
return result;

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.

I am not sure about this observable usage, even if I read about cold observables. Maybe @zuozhiw can give more inputs?

Comment on lines +286 to +299
/**
* get a proxy dictionary: access a local copy of the backend dictionary as an object *synchronously*
* without callbacks or subscriptions.
* All instances of proxy dictionaries are synced (changing one affects the others).
* assignment and deletion of attributes cause requests to be sent to the backend
* and the proxy dictionary only changes if those requests are successful.
* *Warning: proxy dictionaries are synced w/ backend each getAll() and should be correct 99.99% of the time.
* However they may fall out of sync due to unforeseen networking errors.*
* @returns Proxy of a local copy
*/
public forceGetUserDictionary(): UserDictionary {
// gets user dictionary even if local dictionary isn't initialized
return this.proxyUserDictionary();
}

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.

I am concerned about having a local copy of DB initially. I do not fully understand the purpose of this method. Is it used to refresh the local dict copy when an unsync version is detected?

Comment on lines +301 to +311
/**
* get a proxy dictionary: access a local copy of the backend dictionary as an object *synchronously*
* without callbacks or subscriptions.
* All instances of proxy dictionaries are synced (changing one affects the others).
* assignment and deletion of attributes cause requests to be sent to the backend
* and the proxy dictionary only changes if those requests are successful.
* *Warning: proxy dictionaries are synced w/ backend each getAll() and should be correct 99.99% of the time.
* However they may fall out of sync due to unforseen networking errors.*
* @returns Proxy of a local copy once initial getAll() is finished
*/
public getUserDictionaryAsync(): Observable<UserDictionary> {

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 doc indicates this is "synchronous" however the method name indicates the opposite. is it a mistake?

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.

synchronous is supposed to describe the dictionary proxy object: it has synchronous reads and writes
I copied this description from the other getUserDictionary() functions, but I didn't take into account that this could be confusing

Comment on lines +331 to +335
if (error.message === 'Invalid session') {
console.error(error);
} else {
throw error;
}

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.

it appears different errors are being handled differently. what are the possible errors here? maybe for simplicity, just error out or warn out all the errors instead?

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.

I think warn out all errors would be better

Comment on lines +119 to +124
export enum EVENT_TYPE {
GET,
SET,
DELETE,
GET_ALL
}

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 same comment as backend, it's better to be explicit on the name, EVENT_TYPE is too general IMO. Either change the name or you can put this enum inside the service. Same for other type names below as well.

Comment on lines +349 to +375
if (event.key in this.localUserDictionary &&
this.localUserDictionary[event.key] !== event.value) {
console.warn(`[user-dictionary service] Dictionary desynchronized at key "${event.key}": `
+ `locally had ${this.localUserDictionary[event.key]} but remote reported ${event.value}`);
}
this.localUserDictionary[event.key] = event.value;
break;

case EVENT_TYPE.SET:
this.localUserDictionary[event.key] = event.value;
break;

case EVENT_TYPE.DELETE:
delete this.localUserDictionary[event.key];
break;

case EVENT_TYPE.GET_ALL:
if (!isEqual(this.localUserDictionary, event.value) && !isEqual(this.localUserDictionary, {})) {
console.warn(`[user-dictionary service] Dictionary was desynchronized, local had `
+ `${this.localUserDictionary}, but remote reported ${event.value}`);
}
// setting this.localUserDictionary = event.value would not
// change the references to this.localUserDictionary used in all proxy dictionaries
for (const key in this.localUserDictionary) {
delete this.localUserDictionary[key];
}
Object.assign(this.localUserDictionary, event.value);

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.

I understand this part is about CUID operations with the local dictionary copy. It will be good to define methods to make it more readable. The handler of GET and GET_ALL seem to be mergeable (with methods).

const dictionaryService = this;
return {
set(localUserDictionary: Readonly<UserDictionary>, key: string, value: string) {
console.log('set', key, value);

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.

I forgot to remove this print. please remove all prints.

Comment on lines +463 to +466
* @param response UserDictionaryResponse that should be a DictResponse
* @returns object representing copy of backend dictionary
*/
private handleDeleteConfirmationResponse(key: string, response: UserDictionaryResponse): boolean {

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 doc is missing params.

Comment on lines +448 to +451
* @param response UserDictionaryResponse that should be a DictResponse
* @returns object representing copy of backend dictionary
*/
private handleSetConfirmationResponse(key: string, value: string, response: UserDictionaryResponse): boolean {

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 doc is missing params

}
// setting this.localUserDictionary = event.value would not
// change the references to this.localUserDictionary used in all proxy dictionaries
for (const key in this.localUserDictionary) {

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.

tslint complains about TSLint: for (... in ...) statements must be filtered with an if statement(forin)

@Yicong-Huang
Yicong-Huang requested a review from zuozhiw June 19, 2021 02:25
@Yicong-Huang

Copy link
Copy Markdown
Contributor

I am adding @zuozhiw for further review.

@MysteriousChallenger

Copy link
Copy Markdown
Contributor Author

I'd also prefer to take the name UserDictionaryService. The current user-dictionary refers to an old feature which allowed users to upload a dictionary and use it as a data source. I think it's currently not implemented on the user dashboard?

I suggest we rename the current user-dictionary into DictionaryDataService / DataDictionaryService.
Alternately, we could get rid of it entirely. Seems like the server side of this feature (UserDictionaryResource) was deleted already.

@Yicong-Huang Yicong-Huang mentioned this pull request Jun 26, 2021
2 of 3 tasks

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

I've reviewed the PR and made some changes to simplify the logic. This is now good to merge.

@zuozhiw
zuozhiw dismissed Yicong-Huang’s stale review June 27, 2021 16:17

review is now obsolete after the changes

@zuozhiw
zuozhiw merged commit 799858c into master Jun 27, 2021
@zuozhiw
zuozhiw deleted the Albert-UserDictionaryService branch June 27, 2021 16:44
@Yicong-Huang Yicong-Huang added the frontend Changes related to the frontend GUI label Jul 6, 2025
@Yicong-Huang Yicong-Huang removed the gui label Jul 6, 2025
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
This PR is extracted from apache#1041 as step 2 of the User Preset feature.

rebase of picked commits pertaining to UserDictionaryService onto Albert-UserDictionaryResource

UserDictionaryService provides a "dictionary", a persistent collection of string (key, value) pairs for clients that are logged in
Changes from last review (for Yicong)
- Much more code comments
- using new API from User Presets Step 1
- Get/Set/Delete methods return Observables instead of Promises now
- Code should be much more readable because error handling and validation are separated into individual function definitions

Co-authored-by: Yicong Huang <[email protected]>
Co-authored-by: Zuozhi Wang <[email protected]>
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Oct 2, 2026
…e#8817)

### What changes were proposed in this PR?

Removes `dictionaryChangedSubject` from `UserConfigService`: the private
field, its three `.next()` calls in `updateEntry` / `updateDict`, and
the now-unused rxjs `Subject` import. **+8/−49 lines.** There is no
behaviour change. The Subject was private with no getter, so nothing
could subscribe to it.

`updateEntry` and `updateDict` keep their guards, deletes and
assignments; only the emissions go. In the spec, two cases that only
counted emissions are deleted. Two others are kept, with their emission
assertions replaced by behaviour checks, because they cover the
surviving guards: a repeated `set()` still issues a PUT and keeps the
entry, and deleting an absent key leaves the dictionary untouched.

### History

| | |
| --- | --- |
| **Introduced by** | apache#1162 (2021-06-27), "Add UserDictionaryService
(User Presets Step 2)". The field was private from the start, with no
getter or `asObservable()` |
| **Usage removed by** | **never used**. The only readers were spec
cases reaching the private field through `(service as any)` |

It has been unused for over five years.

### Any related issues, documentation, discussions?

Closes apache#8816

### How was this PR tested?

No new tests. The two kept cases now pin the guards' behaviour instead
of emission counts.

From `frontend/`:

- `npx ng test --watch=false --include='**/user-config.service.spec.ts'
--include='**/preset.service.spec.ts'`: 2 files, 68 tests, all pass.
`PresetService` is the only production consumer of `UserConfigService`.
- `yarn format:ci`: clean.
- `npx ng build`: success.

To re-check:

```
git grep -n -i "dictionaryChanged" -- frontend   # no hits
```

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Nov 26, 2026
### What changes were proposed in this PR?

Remove code that nothing uses, or that repeats work already done, across
16 files in the frontend, Amber, the shared config and observability
modules, and the sbt license helper (**+22/−152 lines**). There is no
behavior change.

- **`PresetService`:** `getOperatorPreset`,
`filterOperatorPresetProperties` and the private `ajvStrip` validator
they share have no caller outside their own spec. Their two spec blocks
go with them.
- **`UserConfigService`:** `set` and `delete` return their request
observables, and no caller reads them; `PresetService`, the only caller,
discards both. They now return `void`, so the `shareReplay` carriers and
the `of` import go. Each call still sends its request once and updates
the local dictionary when the request succeeds.
- **Resource registry:** `ResourceDescriptor.setCover` and its dataset
and model implementations have no caller outside the registry's own
spec. The dataset and model pages set a cover through
`DatasetService.updateDatasetCoverImage` and
`ModelService.updateModelCoverImage` directly. The spec drops its
`setCover` call, the matching assertion and the `updateModelCoverImage`
stub, and the workflow descriptor's comment stops naming the hook.
- **`StorageConfig`:** 12 JDBC, Iceberg and S3 name constants that
nothing reads. Every reader, such as `ComputingUnitManagingResource`,
uses the same names from `EnvironmentalVariable`. The four cleanup and
warehouse constants stay, because `StorageConfigSpec` reads them.
- **Telemetry:** `WorkflowMetricsRecorder.init` calls
`WorkflowMetrics.ensureBound()` right after
`setActiveExecutionsSupplier`, which already calls it.
`OtelInit.initialized` only ever holds an `OpenTelemetrySdk`, so it is
now typed that way, and `resetForTest` loses a fallback arm that could
not run.
- **`CollaborationResource`:** the `heartbeat`, `tryLock`, `acquireLock`
and `restoreVersion` patterns bind names that their bodies never read,
so each becomes `_`.
- **Result table:** nothing reads the `#statsRow` template reference.
- **`search-results.component.spec.ts`:** the card-template host imports
`NgTemplateOutlet`, which its template never uses.
- **`TexeraWebApplication`:** drops a commented-out call to
`discardUncommittedChangesOfAllDatasets` and its TODO. That method no
longer exists.
- **`AddMetaInfLicenseFiles`:** drops `import
com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport._`, which
nothing in the helper uses.

| Event | PR / Commit |
| --- | --- |
| Introduced by | `PresetService`: apache#1164 (2022-01-14);
`UserConfigService`: apache#1162 (2021-06-27); resource registry: apache#8299
(2026-08-31); `StorageConfig`: apache#3337 (2025-04-06); telemetry: apache#5375
(2026-10-25) and apache#5376 (2026-10-27); `CollaborationResource`: apache#1427
(2022-02-15); result table: apache#2931 (2024-10-14); search results spec:
apache#6565 (2026-07-20); `TexeraWebApplication`: apache#2391 (2024-02-20),
commented out by apache#2733 (2024-07-15); `AddMetaInfLicenseFiles`: apache#4367
(2026-04-17) |
| Usage removed by | `TexeraWebApplication`: apache#3314 (2025-03-12) deleted
`discardUncommittedChangesOfAllDatasets`. `AddMetaInfLicenseFiles`:
apache#4449 (2026-04-29) removed the last `Universal` reference. Everything
else: unused since introduction. |

As of 2026-11-25:
- No caller has read the `UserConfigService` return values in the more
than 5 years since they were added.
- The two `PresetService` helpers have had no caller outside their spec
for almost 5 years, and the `CollaborationResource` bindings have been
unused for as long.
- The `#statsRow` reference has been unread for over 2 years.
- The commented call has pointed at a deleted method, and the
`StorageConfig` constants have been unread, for over a year and a half
each.
- The Universal import has been unused for almost 7 months.
- The `setCover` hook has had no caller in the almost 3 months it has
existed, and the telemetry duplicates have done nothing in the month
since they were added.

### Any related issues, documentation, discussions?

Closes apache#9695.

### How was this PR tested?

Ran on this branch and on `main` at `d1a0c5e673` (Windows 11; Node 24
with Yarn 4.14.1; JDK 17):

```bash
cd frontend
npx ng test --watch=false --include='**/preset.service.spec.ts' --include='**/user-config.service.spec.ts' --include='**/preset-wrapper.component.spec.ts' --include='**/result-table-frame.component.spec.ts' --include='**/search-results.component.spec.ts' --include='**/resource-registry.service.spec.ts'
npx tsc --noEmit -p src/tsconfig.app.json
npx tsc --noEmit -p src/tsconfig.spec.json
yarn prettier-eslint --list-different $(git diff --name-only --relative origin/main -- src)
yarn eslint $(git diff --name-only --relative origin/main -- src)
cd ..
sbt Config/test Observability/test "WorkflowExecutionService/testOnly org.apache.texera.web.resource.CollaborationResourceSpec org.apache.texera.web.observability.WorkflowMetricsRecorderSpec"
sbt Config/scalafmtCheckAll Observability/scalafmtCheckAll WorkflowExecutionService/scalafmtCheckAll "Config/scalafixAll --check" "Observability/scalafixAll --check" "WorkflowExecutionService/scalafixAll --check"
```

- **Frontend:** the six specs run 199 tests on this branch and 206 on
`main`, all passing. The 7 extra on `main` are the deleted helpers' own
spec cases; every other test keeps its name and outcome. Both
typechecks, prettier-eslint and ESLint pass.
- **Scala:** the `Config` and `Observability` suites and the two Amber
specs run 212 tests, all passing on both sides with the same names and
outcomes. scalafmt and scalafix pass for all three projects.
- Every sbt run compiles the build definition, so
`AddMetaInfLicenseFiles.scala` compiled with and without the import.

To re-check, both commands return no hits on this branch:

```bash
git grep -nwE "getOperatorPreset|filterOperatorPresetProperties|ajvStrip|setCover" -- frontend/src
git grep -nE "ENV_(JDBC|ICEBERG|S3)_" -- common/config/src/main/scala/org/apache/texera/common/config/StorageConfig.scala
```

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature frontend Changes related to the frontend GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants