Skip to content

Commit

Permalink
fix(backend): fix cache of stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Jul 9, 2024
1 parent 33222b6 commit f117c22
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fileignoreconfig:
- filename: packages/backend/src/modules/portail-usagers/controllers/portail-usagers-manager/portail-usagers-manager.controller.ts
checksum: 6cb66d899577621ac9f796b2fde88a68263b7422c3f369854d94236c15c0807f
- filename: packages/backend/src/stats/services/publicStats.service.ts
checksum: 157a960c629659937e57bb878abf8f14a91e361c599e630a6b0b80d28df81658
checksum: cdacf3bc7647bc137155700d9da75cd607dc9a868aa01f7209d22ef2c3472ff9
- filename: packages/backend/src/usagers/controllers/export-structure-usagers.controller.ts
checksum: 0a10c492e64567f0309c24e270d7f5a18835acb26e72650337e8a18476cf271e
- filename: packages/backend/src/usagers/services/xlsx-structure-usagers-renderer/renderStructureUsagersRows.ts
Expand Down
22 changes: 8 additions & 14 deletions packages/backend/src/stats/services/publicStats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,19 @@ export class PublicStatsService implements OnModuleInit {
updateCache?: boolean;
regionId?: string;
}): Promise<PublicStats> {
const key = regionId ? "publics-stats-" + regionId : "public-stats";
const key = regionId ? "public-stats-" + regionId : "public-stats";

const value = await publicStatsCacheRepository
.createQueryBuilder()
.select(["stats", "key", "uuid"])
.createQueryBuilder("public_stats_cache")
.where(
`to_date(to_char("createdAt", 'YYYY-MM-DD'), 'YYYY-MM-DD') = to_date(:date, 'YYYY-MM-DD')`,
{ date: new Date() }
`"createdAt" > now() - interval '1 day' and "createdAt" <= now() and key = :key`,
{ key }
)
.where("key= :key", { key })
.orderBy(`"createdAt"`, "DESC")
.getOne();

if (value && !updateCache) {
return value as unknown as PublicStats;
return value.stats;
}

const publicStats = new PublicStats();
Expand Down Expand Up @@ -140,13 +139,8 @@ export class PublicStatsService implements OnModuleInit {
) {
if (previousValue?.uuid) {
await publicStatsCacheRepository.update(
{
uuid: previousValue?.uuid,
},
{
key,
stats: publicStats,
}
{ uuid: previousValue?.uuid },
{ stats: publicStats }
);
} else {
await publicStatsCacheRepository.save({
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/assets/files/news.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "new",
"categorie": "Activation du portail domicilié Mon DomiFa au niveau de la structure",
"message": [
"Une nouvelle page d'activation du portail domicilié est disponible sur le lien suivant et vous donne davantage d'informations sur le contenu du portal : https://domifa.fabrique.social.gouv.fr/structures/portail-usager"
"Une nouvelle page d'activation du portail domicilié 'Mon DomiFa' est disponible sur le lien suivant et vous donne davantage d'informations sur le contenu du portal : https://domifa.fabrique.social.gouv.fr/structures/portail-usager"
]
},
{
Expand Down

0 comments on commit f117c22

Please sign in to comment.