Skip to content

Commit ac7337c

Browse files
committed
chore(product): loại bỏ CdnPurgeService và cập nhật logic trong các service
- Xóa CdnPurgeService khỏi dự án để giảm thiểu độ phức tạp và cải thiện hiệu suất. - Cập nhật các service liên quan để loại bỏ các tham chiếu đến CdnPurgeService, đảm bảo tính nhất quán trong logic xử lý sản phẩm. - Cải tiến logic lấy ngôn ngữ trong ProductService để sử dụng giá trị mặc định 'vi'. - Sửa lỗi chính tả trong header cache của ProductController.
1 parent 998f3ff commit ac7337c

5 files changed

Lines changed: 5 additions & 50 deletions

File tree

src/routes/product/manage-product/manage-product.service.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ import { RoleName } from 'src/shared/constants/role.constant'
1212
import { I18nTranslations } from 'src/shared/languages/generated/i18n.generated'
1313
import { AccessTokenPayload } from 'src/shared/types/jwt.type'
1414
import { RedisService } from 'src/shared/services/redis.service'
15-
import { CdnPurgeService } from 'src/shared/services/cdn-purge.service'
1615
import { CacheEvict } from 'src/shared/decorators/cacheable.decorator'
1716

1817
@Injectable()
1918
export class ManageProductService {
2019
constructor(
2120
private productRepo: ProductRepo,
2221
private i18n: I18nService<I18nTranslations>,
23-
private readonly redisService: RedisService,
24-
private readonly cdnPurgeService: CdnPurgeService
22+
private readonly redisService: RedisService
2523
) {}
2624

2725
/**
@@ -101,8 +99,7 @@ export class ManageProductService {
10199
createdById: user.userId,
102100
data
103101
})
104-
// Purge CDN theo Surrogate-Key (nếu có cấu hình)
105-
await this.cdnPurgeService.purgeBySurrogateKeys(['product:list', `product:detail:${product.data.id}`])
102+
106103
return {
107104
message: this.i18n.t('product.product.success.CREATE_SUCCESS'),
108105
data: product.data
@@ -137,7 +134,6 @@ export class ManageProductService {
137134
updatedById: user.userId,
138135
data
139136
})
140-
await this.cdnPurgeService.purgeBySurrogateKeys(['product:list', `product:detail:${productId}`])
141137
return {
142138
message: this.i18n.t('product.product.success.UPDATE_SUCCESS'),
143139
data: updatedProduct
@@ -169,7 +165,6 @@ export class ManageProductService {
169165
id: productId,
170166
deletedById: user.userId
171167
})
172-
await this.cdnPurgeService.purgeBySurrogateKeys(['product:list', `product:detail:${productId}`])
173168
return {
174169
message: this.i18n.t('product.product.success.DELETE_SUCCESS')
175170
}

src/routes/product/product.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ProductController {
2929
const sMaxBase = 3600
3030
const jitter = Math.round(sMaxBase * (Math.random() * 0.2 - 0.1)) // ±10%
3131
const sMaxAge = sMaxBase + jitter
32-
return `public, max-age=${maxAge}, s-maxage=${sMaxAge}, stale-while-revalidate=900`
32+
return `public, m ax-age=${maxAge}, s-maxage=${sMaxAge}, stale-while-revalidate=900`
3333
})()}`
3434
)
3535
@Header('Vary', 'Accept-Language, Accept-Encoding')

src/routes/product/product.module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { Module } from '@nestjs/common'
2-
import { CdnPurgeService } from 'src/shared/services/cdn-purge.service'
32
import { ManageProductController } from 'src/routes/product/manage-product/manage-product.controller'
43
import { ManageProductService } from 'src/routes/product/manage-product/manage-product.service'
54
import { ProductController } from 'src/routes/product/product.controller'
65
import { ProductRepo } from 'src/routes/product/product.repo'
76
import { ProductService } from 'src/routes/product/product.service'
87

98
@Module({
10-
providers: [ProductService, ManageProductService, ProductRepo, CdnPurgeService],
9+
providers: [ProductService, ManageProductService, ProductRepo],
1110
controllers: [ProductController, ManageProductController],
1211
exports: [ProductRepo]
1312
})

src/routes/product/product.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class ProductService {
8888
scope: 'module',
8989
moduleName: 'ProductModule',
9090
keyGenerator: (props: { productId: string }) => {
91-
const lang = I18nContext.current()?.lang || 'vi'
91+
const lang = 'vi'
9292
return `${props.productId}:${lang}:public`
9393
}
9494
})

src/shared/services/cdn-purge.service.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)