@@ -301,7 +301,13 @@ export default class Engine {
301301 canContinue = false ;
302302 }
303303 }
304- return oneHook [ action ] ( newMd , actionArgs , this . markdownParams ) ;
304+ // const time = Date.now();
305+ const ret = oneHook [ action ] ( newMd , actionArgs , this . markdownParams ) ;
306+ // const cost = Date.now() - time;
307+ // if (cost > 50) {
308+ // console.log(`hook ${oneHook.getName()} ${action} cost ${Date.now() - time}ms`);
309+ // }
310+ return ret ;
305311 } , $md ) ;
306312 } catch ( e ) {
307313 throw new NestedError ( e ) ;
@@ -316,13 +322,17 @@ export default class Engine {
316322 return this . hash ( str ) ;
317323 }
318324
325+ sha256 ( str ) {
326+ return CryptoJS . SHA256 ( str ) . toString ( ) ;
327+ }
328+
319329 /**
320330 * 计算哈希值
321331 * @param {String } str 被计算的字符串
322332 * @returns {String } 哈希值
323333 */
324334 hash ( str ) {
325- // 当缓存队列比较大时,随机抛弃500个缓存
335+ // 当缓存队列比较大时,随机抛弃一些缓存
326336 if ( this . hashStrMap . size > 2000 ) {
327337 const keys = Array . from ( this . hashStrMap . keys ( ) ) . slice ( 0 , 200 ) ;
328338 keys . forEach ( ( key ) => this . hashStrMap . delete ( key ) ) ;
@@ -366,11 +376,18 @@ export default class Engine {
366376 this . cachedBigData [ cacheKey ] = m2 ;
367377 return `${ m1 } ${ cacheKey } }` ;
368378 } ) ;
369- $md = $md . replace ( longTextReg , ( whole , m1 , m2 ) => {
370- const cacheKey = `bigDataBegin${ this . hash ( m2 ) } bigDataEnd` ;
371- this . cachedBigData [ cacheKey ] = m2 ;
372- return `${ m1 } ${ cacheKey } }` ;
373- } ) ;
379+
380+ const tmpArr = $md . split ( / \n / ) ;
381+ for ( let i = 0 ; i < tmpArr . length ; i ++ ) {
382+ if ( tmpArr [ i ] . length > 6000 ) {
383+ tmpArr [ i ] = tmpArr [ i ] . replace ( longTextReg , ( whole ) => {
384+ const cacheKey = `bigDataBegin${ this . hash ( whole ) } bigDataEnd` ;
385+ this . cachedBigData [ cacheKey ] = whole ;
386+ return cacheKey ;
387+ } ) ;
388+ }
389+ }
390+ $md = tmpArr . join ( '\n' ) ;
374391 $md = $md . replace ( pasteWrapperReg , '' ) ;
375392 return $md ;
376393 }
0 commit comments