Skip to content

Incorrect behaivor of 'alwaysEnabled: true' after change from issue #9023 #9910

@myst-ho

Description

@myst-ho

Issue description

alwaysEnabled by definition "If set to true then queries (using find methods and QueryBuilder's methods) will always be cached." should cache the query without explicitly stating 'cache: true' or 'cache: false'. However, version 0.3.12, when alwaysEnabled=true and cache is not defined in query, the result is not cached.

Expected Behavior

While alwaysEnabled is set to true

  • cache (in query) = false, result should NOT be cached
  • cache (in query) = true, result should be cached
  • cache (in query) = undefined, whether the result should be cached should depend on global value alwaysEnabled

Actual Behavior

When alwaysEnabled=true and cache is not defined in query, the result is not cached.

Steps to reproduce

  1. Set the global alwaysEnabled to true
  2. Do not set the cache in query
  3. Run the query by using findOne (or other find*)

My Environment

Dependency Version
Operating System MacOS 13.2.1
Node.js version 18.10
Typescript version 4.9.5
TypeORM version 0.3.12

Additional Context

The issue seems coming from recent change that trying to fix issue #9023 (https://github.com/typeorm/typeorm/pull/9731/files)

However, it does not consider the case when this.expressionMap.cache is undefined in cacheOptions.alwaysEnabled && this.expressionMap.cache. Only this.expressionMap.cache is false should override the global setting in this specific query.
image

This is my interoperation, and please feel to correct me.

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

I am willing to help but I may not have enough time to understand the background and fix it correctly. Anyone from the community would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions