@@ -3,15 +3,18 @@ import UtilPath from './path.js'
3
3
import UtilHash from './hash.js'
4
4
import UtilProgress from './progress.js'
5
5
6
- function getFileSummary ( base = '' , paths = [ ] , queue = null ) {
6
+ async function getFileSummary ( base = '' , paths = [ ] , queue = null ) {
7
7
const countTotal = paths . length
8
8
const progress = UtilProgress . createProgressbar ( { total : countTotal } )
9
9
const summary = [ ]
10
+ const hashChunkConfig = UtilHash . getHashChunkPlots ( { name : 'single plot' , offset : 0 , limit : 100 * 1024 } )
10
11
11
12
_ . each ( paths , async path => {
12
13
await queue . add ( ( ) => {
13
14
const filename = UtilPath . relative ( base , path )
14
- const md5 = UtilHash . getHash ( path , { offset : 0 , limit : 100 * 1024 } )
15
+ const md5 = UtilHash . getHashByChunks ( path , {
16
+ chunks : hashChunkConfig
17
+ } )
15
18
16
19
const pack = {
17
20
path,
@@ -24,6 +27,44 @@ function getFileSummary (base = '', paths = [], queue = null) {
24
27
} )
25
28
} )
26
29
30
+ await queue . onIdle ( )
31
+
32
+ return summary
33
+ }
34
+
35
+ async function rehashFileSummary ( files = [ ] , queue = null ) {
36
+ const countTotal = files . length
37
+ const progress = UtilProgress . createProgressbar ( { total : countTotal } )
38
+ const summary = [ ]
39
+
40
+ _ . each ( files , async file => {
41
+ await queue . add ( ( ) => {
42
+ const path = file . path
43
+ const chunkConfig = UtilHash . getHashChunkPlots ( {
44
+ name : 'distribution plots' ,
45
+ file : path ,
46
+ chunks : 10 ,
47
+ offset : 0 ,
48
+ limit : 10 * 1024
49
+ } )
50
+ const filename = file . filename
51
+ const md5 = UtilHash . getHashByChunks ( path , {
52
+ chunks : chunkConfig
53
+ } )
54
+
55
+ const pack = {
56
+ path,
57
+ filename,
58
+ md5
59
+ }
60
+
61
+ summary . push ( pack )
62
+ progress . tick ( )
63
+ } )
64
+ } )
65
+
66
+ await queue . onIdle ( )
67
+
27
68
return summary
28
69
}
29
70
@@ -62,6 +103,21 @@ function getCompareSummary (lhs = [], rhs = []) {
62
103
return summary
63
104
}
64
105
106
+ async function revalidateCompareSummary ( summary = [ ] , lhsQueue = null , rhsQueue = null ) {
107
+ const summaryUnsame = _ . filter ( summary , v => v . type !== 'same' )
108
+ const summarySame = _ . filter ( summary , v => v . type === 'same' )
109
+
110
+ const lhs = _ . chain ( summarySame ) . map ( v => v . lhs || [ ] ) . flattenDeep ( ) . value ( )
111
+ const lhsRehashed = await rehashFileSummary ( lhs , lhsQueue )
112
+ const rhs = _ . chain ( summarySame ) . map ( v => v . rhs || [ ] ) . flattenDeep ( ) . value ( )
113
+ const rhsRehashed = await rehashFileSummary ( rhs , rhsQueue )
114
+ const summaryRehashed = getCompareSummary ( lhsRehashed , rhsRehashed )
115
+
116
+ const summaryNew = _ . concat ( [ ] , summaryUnsame , summaryRehashed )
117
+
118
+ return summaryNew
119
+ }
120
+
65
121
function getCompareReport ( summary = [ ] ) {
66
122
const template = `<!DOCTYPE html>
67
123
<html>
@@ -190,6 +246,8 @@ function getCompareReport (summary = []) {
190
246
191
247
export default {
192
248
getFileSummary,
249
+ rehashFileSummary,
193
250
getCompareSummary,
251
+ revalidateCompareSummary,
194
252
getCompareReport
195
253
}
0 commit comments