[READ-ONLY] a fast, modern browser for the npm registry

bug: small bugfixes for likes (#897)

authored by baileytownsend.dev and committed by

GitHub 05483f5c c3d63c49

+16 -3
+3
server/api/social/like.delete.ts
··· 31 31 }) 32 32 const result = await likesUtil.unlikeAPackageAndReturnLikes(body.packageName, loggedInUsersDid) 33 33 return result 34 + } else { 35 + // Always unlike in the cache if this endpoint is called. May be a mismatch 36 + await likesUtil.setUnlikeInCache(body.packageName, loggedInUsersDid) 34 37 } 35 38 36 39 console.warn(
+13 -3
server/utils/atproto/utils/likes.ts
··· 168 168 let totalLikes = await this.cache.get<number>(totalLikesKey) 169 169 if (!totalLikes) { 170 170 totalLikes = await this.constellationLikes(subjectRef) 171 - totalLikes = totalLikes + 1 172 - await this.cache.set(totalLikesKey, totalLikes, CACHE_MAX_AGE) 173 171 } 172 + totalLikes = totalLikes + 1 173 + await this.cache.set(totalLikesKey, totalLikes, CACHE_MAX_AGE) 174 + 174 175 // We already know the user has not liked the package before so set in the cache 175 176 await this.cache.set(CACHE_USER_LIKES_KEY(packageName, usersDid), true, CACHE_MAX_AGE) 176 177 return { ··· 213 214 } 214 215 215 216 /** 217 + * Access to unlike a package for a user in the cache. 218 + * @param packageName 219 + * @param usersDid 220 + */ 221 + async setUnlikeInCache(packageName: string, usersDid: string) { 222 + await this.cache.set(CACHE_USER_LIKES_KEY(packageName, usersDid), false, CACHE_MAX_AGE) 223 + } 224 + 225 + /** 216 226 * At this point you should have checked if the user had a record for the package on the network and removed it before updating the cache 217 227 * @param packageName 218 228 * @param usersDid ··· 230 240 await this.cache.set(totalLikesKey, totalLikes, CACHE_MAX_AGE) 231 241 232 242 //Clean up 233 - await this.cache.set(CACHE_USER_LIKES_KEY(packageName, usersDid), false, CACHE_MAX_AGE) 243 + await this.setUnlikeInCache(packageName, usersDid) 234 244 await this.cache.delete(CACHE_USERS_BACK_LINK(packageName, usersDid)) 235 245 236 246 return {