Skip to content

Commit

Permalink
Merge pull request #168 from thanhdanh27600/staging
Browse files Browse the repository at this point in the history
fix update not change og
  • Loading branch information
thanhdanh27600 authored Sep 12, 2023
2 parents 1b167e6 + 1d9e196 commit 606f50d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/controllers/forward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export const postProcessForward = async (payload: ForwardMeta, res?: NextApiResp
return cacheMissed ? badRequest(res) : null;
}

// write back to cache
shortenCacheService.postShortenHash(history);

await prisma.urlForwardMeta.upsert({
where: {
userAgent_ip_urlShortenerHistoryId: {
Expand All @@ -72,8 +75,6 @@ export const postProcessForward = async (payload: ForwardMeta, res?: NextApiResp
});

if (cacheMissed) {
// write back to cache
await shortenCacheService.postShortenHash(history);
return res.status(HttpStatusCode.OK).json({ history });
}
};
2 changes: 1 addition & 1 deletion src/controllers/shorten/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const handler = api<ShortenUrl>(
},
});
// update cache
shortenCacheService.updateShortenHash(hash);
shortenCacheService.expireShortenHash(hash);
// remove used tag
if (ogImgPublicId) {
cloudinaryInstance.uploader.remove_tag('unused', ogImgPublicId).then().catch();
Expand Down
2 changes: 1 addition & 1 deletion src/services/cacheServices/shorten.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ShortenCache {
await Promise.all([redis.hset(hashKey, data), redis.expire(hashKey, LIMIT_SHORTENED_SECOND)]);
}

updateShortenHash(hash: string) {
expireShortenHash(hash: string) {
const hashKey = getRedisKey(REDIS_KEY.MAP_SHORTEN_BY_HASH, hash);
redis.expire(hashKey, -1).then().catch();
}
Expand Down

0 comments on commit 606f50d

Please sign in to comment.