mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
parent
73ee70b331
commit
173910ed79
3
src/cache/DbQueryResultCache.ts
vendored
3
src/cache/DbQueryResultCache.ts
vendored
@ -158,6 +158,7 @@ export class DbQueryResultCache implements QueryResultCache {
|
||||
? new MssqlParameter(options.identifier, "nvarchar")
|
||||
: options.identifier,
|
||||
})
|
||||
.cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
|
||||
.getRawOne()
|
||||
} else if (options.query) {
|
||||
if (this.connection.driver.options.type === "oracle") {
|
||||
@ -168,6 +169,7 @@ export class DbQueryResultCache implements QueryResultCache {
|
||||
)}, :query) = 0`,
|
||||
{ query: options.query },
|
||||
)
|
||||
.cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
|
||||
.getRawOne()
|
||||
}
|
||||
|
||||
@ -179,6 +181,7 @@ export class DbQueryResultCache implements QueryResultCache {
|
||||
? new MssqlParameter(options.query, "nvarchar")
|
||||
: options.query,
|
||||
})
|
||||
.cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
|
||||
.getRawOne()
|
||||
}
|
||||
|
||||
|
||||
@ -261,8 +261,9 @@ export class QueryExpressionMap {
|
||||
|
||||
/**
|
||||
* Indicates if query result cache is enabled or not.
|
||||
* It is undefined by default to avoid overriding the `alwaysEnabled` config
|
||||
*/
|
||||
cache: boolean = false
|
||||
cache?: boolean
|
||||
|
||||
/**
|
||||
* Time in milliseconds in which cache will expire.
|
||||
|
||||
@ -3770,7 +3770,7 @@ export class SelectQueryBuilder<Entity extends ObjectLiteral>
|
||||
(cacheOptions.alwaysEnabled &&
|
||||
this.expressionMap.cache !== false) ||
|
||||
// ...or it's enabled locally explicitly.
|
||||
this.expressionMap.cache
|
||||
this.expressionMap.cache === true
|
||||
let cacheError = false
|
||||
if (this.connection.queryResultCache && isCachingEnabled) {
|
||||
try {
|
||||
|
||||
10
test/github-issues/9910/entity/User.ts
Normal file
10
test/github-issues/9910/entity/User.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column } from "../../../../src"
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
name: string
|
||||
}
|
||||
58
test/github-issues/9910/issue-9910.ts
Normal file
58
test/github-issues/9910/issue-9910.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import "reflect-metadata"
|
||||
import { expect } from "chai"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../utils/test-utils"
|
||||
import { DataSource } from "../../../src/data-source/DataSource"
|
||||
import { User } from "./entity/User"
|
||||
|
||||
describe("github issues > #9910 Incorrect behaivor of 'alwaysEnabled: true' after change from issue #9023", () => {
|
||||
let connections: DataSource[]
|
||||
before(
|
||||
async () =>
|
||||
(connections = await createTestingConnections({
|
||||
entities: [__dirname + "/entity/*{.js,.ts}"],
|
||||
cache: {
|
||||
alwaysEnabled: true,
|
||||
},
|
||||
})),
|
||||
)
|
||||
beforeEach(() => reloadTestingDatabases(connections))
|
||||
after(() => closeTestingConnections(connections))
|
||||
|
||||
it("should automatically cache if alwaysEnabled", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
if (connection.driver.options.type === "spanner") {
|
||||
return
|
||||
}
|
||||
const user1 = new User()
|
||||
user1.name = "Foo"
|
||||
await connection.manager.save(user1)
|
||||
|
||||
const users1 = await connection
|
||||
.createQueryBuilder(User, "user")
|
||||
.getMany()
|
||||
expect(users1.length).to.be.equal(1)
|
||||
|
||||
const user2 = new User()
|
||||
user2.name = "Bar"
|
||||
await connection.manager.save(user2)
|
||||
|
||||
// result should be cached and second user should not be retrieved
|
||||
const users2 = await connection
|
||||
.createQueryBuilder(User, "user")
|
||||
.getMany()
|
||||
expect(users2.length).to.be.equal(1)
|
||||
|
||||
// with cache explicitly disabled, the second user should be retrieved
|
||||
const users3 = await connection
|
||||
.createQueryBuilder(User, "user")
|
||||
.cache(false)
|
||||
.getMany()
|
||||
expect(users3.length).to.be.equal(2)
|
||||
}),
|
||||
))
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user