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

Feature: Add new load paths to load only if data has not previously been loaded #144

Closed
jrista opened this issue Aug 14, 2020 · 2 comments · Fixed by #148
Closed

Feature: Add new load paths to load only if data has not previously been loaded #144

jrista opened this issue Aug 14, 2020 · 2 comments · Fixed by #148
Assignees
Labels
approved Approved for Implementation enhancement New feature or request
Milestone

Comments

@jrista
Copy link
Contributor

jrista commented Aug 14, 2020

When loading entities with any of the existing load actions, the loads will always occur and will always call the API. There may be times, such as when loading lookup tables, when the load should only occur if data has not been loaded previously.

This proposal recommends introducing a new set of actions for loads, alongside the existing actions, that would only actually be dispatched if no data has been previously loaded for the specified entity.

A new set of actions is proposed to maintain backwards compatibility and function, method and constructor signature standard with existing actions. Modifying existing load actions would be possible by adding a new parameter to allow the developer to flag whether they want to load only if data has not been previously loaded. That would introduce a breaking signature change to all of the load actions and related facade methods. A new set of actions ensures the new functionality can be introduced without breaking any existing use cases.

The proposed actions:

LoadIfMissing
LoadAllIfMissing
LoadManyIfMissing

Only initiating actions should be necessary, as these new actions would be filtered in the corresponding effects if the loadedAt timestamp for the given entity is not nullish, thus preventing the load from actually occurring. Further, these new actions should in turn dispatch their corresponding sibling actions, rather than calling the entity service directly. This will ensure that the existing load flows will be utilized if the loadedAt timestamps are indeed nullish.

@jrista jrista added enhancement New feature or request approved Approved for Implementation labels Aug 14, 2020
@jrista jrista added this to the 0.6.0 Alpha 1 milestone Aug 14, 2020
@jrista jrista self-assigned this Aug 14, 2020
@jrista jrista modified the milestones: 0.6.0 Alpha 1, 0.5.0 Beta 2 Aug 27, 2020
@jrista
Copy link
Contributor Author

jrista commented Aug 30, 2020

After diving into an initial implementation of this, I think expansion of the feature is appropriate. Instead of just loading data if it is missing, which doesn't quite work as simplistically as it sounds for anything other than LoadAll, I think a it should be re-termed *IfNecessary, with necessity being based on more than simply if a loadedAt timestamp or data exists in state for the given entity.

Each of the loads would need to be tuned uniquely for the kind of data being loaded. Data would only be loaded if necessary when each of the necessary criteria for a given type of load had been verified:

LoadAllIfNecessary:

  • loadedAt timestamp in state is null or past configurable threshold
  • potentially: specified criteria does not exist in state (new tracking data required)

LoadIfNecessary:

  • entity with given key does not exist in state;
  • potentially: loadedAt for that entity null or past configurable threshold (new tracking data required)

LoadManyIfNecessary:

  • loadedAt timestamp in state is null or past configurable threshold
  • entities loaded with specified criteria do not exist in state (new tracking data required)

LoadPageIfNecessary:

  • loadedAt timestamp in state is null or past configurable threshold
  • current page info in state is either non-existent, or does not match current page info

LoadRangeIfNecessary:

  • loadedAt timestamp in state is null or past configurable threshold
  • current range info in state is either non-existent, or does not intersect range being loaded

@jrista
Copy link
Contributor Author

jrista commented Aug 30, 2020

To support dynamic loading based on the loadedAt timestamp, each of the IfNecessary actions would also allow a maxAge to be passed, which would check if the loadedAt timestamp plus the specified maxAge is in the past. If so, then the load would be issued, otherwise it would be stopped.

Additionally, for each entity, a defaultMaxAge could be specified on the @Entity decorator to configure a default age for each entity.

jrista pushed a commit that referenced this issue Aug 30, 2020
 * Refactor all actions into more files for easier management
   * Loads into load-*-actions.ts
   * CUURDS into create|update|upsert|replace|delete-actions.ts
   * DeleteByKeys into delete-by-key-actions.ts
   * Edits into edit-actions.ts
   * Selections into selection-actions.ts
   * Deselections into deselection-actions.ts
 + Add new *IfNecessary loader actions for each type of load
 + Add tsdoc to all load actions
 * Update library index/public api to reference all actions from new files
 * Update all otehr action references throughout library
 ^ Bump library version to 0.5.0-beta.3

Phase #1: This is an initial refactoring of action files for the if-necessary work

Issue #144
@jrista jrista linked a pull request Aug 30, 2020 that will close this issue
@jrista jrista modified the milestones: 0.5.0 Beta 2, 0.5.0 Beta 3 Aug 30, 2020
jrista pushed a commit that referenced this issue Aug 30, 2020
 * Introduce to `defaultMaxAge` to IEntityOptions
 + Add EntityAge with predefined common ages for use with `defaultMaxAge`
 * Update @entity decorator to support passing name in only or options or both
 > Move key decorator tokens into entity-tokens.ts
 > Extract entity decorator into its own file entity-decorator.ts
 > Extract key decorator into its own file key-decorator.ts
 * Update index/public api to reference all exports from new locations
 * Added EntityAge enum to public api
 * Removed all imports from '../..'

Issues #144 #141
jrista pushed a commit that referenced this issue Aug 30, 2020
 * Introduce to `defaultMaxAge` to IEntityOptions
 + Add EntityAge with predefined common ages for use with `defaultMaxAge`
 * Update @entity decorator to support passing name in only or options or both
 > Move key decorator tokens into entity-tokens.ts
 > Extract entity decorator into its own file entity-decorator.ts
 > Extract key decorator into its own file key-decorator.ts
 * Update index/public api to reference all exports from new locations
 * Added EntityAge enum to public api
 * Removed all imports from '../..'

Issues #144 #141
jrista pushed a commit that referenced this issue Aug 30, 2020
 * Introduce to `defaultMaxAge` to IEntityOptions
 + Add EntityAge with predefined common ages for use with `defaultMaxAge`
 * Update @entity decorator to support passing name in only or options or both
 > Move key decorator tokens into entity-tokens.ts
 > Extract entity decorator into its own file entity-decorator.ts
 > Extract key decorator into its own file key-decorator.ts
 * Update index/public api to reference all exports from new locations
 * Added EntityAge enum to public api
 * Removed all imports from '../..'

Issues #144 #141
jrista pushed a commit that referenced this issue Aug 30, 2020
 * Introduce to `defaultMaxAge` to IEntityOptions
 + Add EntityAge with predefined common ages for use with `defaultMaxAge`
 * Update @entity decorator to support passing name in only or options or both
 > Move key decorator tokens into entity-tokens.ts
 > Extract entity decorator into its own file entity-decorator.ts
 > Extract key decorator into its own file key-decorator.ts
 * Update index/public api to reference all exports from new locations
 * Added EntityAge enum to public api
 * Removed all imports from '../..'

Issues #144 #141
jrista pushed a commit that referenced this issue Aug 31, 2020
 + Add LoadIfNecessary action
 + Add LoadAllIfNecessary action
 + Add LoadManyIfNecessary action
 + Add LoadPageIfNecessary action
 + Add LoadRangeIfNecessary action
 * Export new actions from public api
 + Add new operators for if necessary loads
 + Add new effects for if necessary loads
 * Include new effects in standard modules
 * Export new effects from public api
 + Add stateNameOfEntity utility function
 * Update builders to use new entityStateName function

Issue #144
jrista pushed a commit that referenced this issue Sep 2, 2020
 + Add LoadIfNecessary action
 + Add LoadAllIfNecessary action
 + Add LoadManyIfNecessary action
 + Add LoadPageIfNecessary action
 + Add LoadRangeIfNecessary action
 * Export new actions from public api
 + Add new operators for if necessary loads
 + Add new effects for if necessary loads
 * Include new effects in standard modules
 * Export new effects from public api
 + Add stateNameOfEntity utility function
 * Update builders to use new entityStateName function

Issue #144
@jrista jrista closed this as completed Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved for Implementation enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant