Commit 382261f 1 parent 8a57af1 commit 382261f Copy full SHA for 382261f
File tree 1 file changed +9
-3
lines changed
api/src/devcomp/infrastructure/repositories
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import { NotFoundError } from '../../../shared/domain/errors.js';
4
4
import { LearningContentResourceNotFound } from '../../../shared/domain/errors.js' ;
5
5
import { ModuleFactory } from '../factories/module-factory.js' ;
6
6
7
+ const memoizedModuleVersions = new Map ( ) ;
8
+
7
9
async function getBySlug ( { slug, moduleDatasource } ) {
8
10
try {
9
11
const moduleData = await moduleDatasource . getBySlug ( slug ) ;
@@ -24,9 +26,13 @@ async function list({ moduleDatasource }) {
24
26
}
25
27
26
28
function _computeModuleVersion ( moduleData ) {
27
- const hash = crypto . createHash ( 'sha256' ) ;
28
- hash . update ( JSON . stringify ( moduleData ) ) ;
29
- return hash . copy ( ) . digest ( 'hex' ) ;
29
+ if ( ! memoizedModuleVersions . has ( moduleData . slug ) ) {
30
+ const hash = crypto . createHash ( 'sha256' ) ;
31
+ hash . update ( JSON . stringify ( moduleData ) ) ;
32
+ const version = hash . copy ( ) . digest ( 'hex' ) ;
33
+ memoizedModuleVersions . set ( moduleData . slug , version ) ;
34
+ }
35
+ return memoizedModuleVersions . get ( moduleData . slug ) ;
30
36
}
31
37
32
38
export { getBySlug , list } ;
You can’t perform that action at this time.
0 commit comments