@@ -168,9 +168,10 @@ export class PackageLikesUtils {
168168 let totalLikes = await this . cache . get < number > ( totalLikesKey )
169169 if ( ! totalLikes ) {
170170 totalLikes = await this . constellationLikes ( subjectRef )
171- totalLikes = totalLikes + 1
172- await this . cache . set ( totalLikesKey , totalLikes , CACHE_MAX_AGE )
173171 }
172+ totalLikes = totalLikes + 1
173+ await this . cache . set ( totalLikesKey , totalLikes , CACHE_MAX_AGE )
174+
174175 // We already know the user has not liked the package before so set in the cache
175176 await this . cache . set ( CACHE_USER_LIKES_KEY ( packageName , usersDid ) , true , CACHE_MAX_AGE )
176177 return {
@@ -212,6 +213,15 @@ export class PackageLikesUtils {
212213 }
213214 }
214215
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+
215225 /**
216226 * 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
217227 * @param packageName
@@ -230,7 +240,7 @@ export class PackageLikesUtils {
230240 await this . cache . set ( totalLikesKey , totalLikes , CACHE_MAX_AGE )
231241
232242 //Clean up
233- await this . cache . set ( CACHE_USER_LIKES_KEY ( packageName , usersDid ) , false , CACHE_MAX_AGE )
243+ await this . setUnlikeInCache ( packageName , usersDid )
234244 await this . cache . delete ( CACHE_USERS_BACK_LINK ( packageName , usersDid ) )
235245
236246 return {
0 commit comments