1- /**
2- * @typedef {object } ResourceMetadata
3- * @property {string } integrity Content integrity of the resource
4- * @property {number } lastModified Last modified timestamp (mtimeMs)
5- * @property {number } inode Inode number of the resource
6- * @property {number } size Size of the resource in bytes
7- */
8-
9- const PERF_TRACKING = ! ! process . env . UI5_CACHE_PERF ;
10- const perfCounters = {
11- calls : 0 ,
12- shortCircuitTrue : 0 ,
13- sizeMismatch : 0 ,
14- inodeMismatch : 0 ,
15- integrityFallback : 0 ,
16- } ;
17- export { perfCounters as isResourceUnchangedCounters } ;
18-
191/**
202 * Determines if a resource has changed compared to cached metadata
213 *
@@ -25,7 +7,8 @@ export {perfCounters as isResourceUnchangedCounters};
257 *
268 * @public
279 * @param {@ui5/fs/Resource } resource Resource instance to compare
28- * @param {ResourceMetadata } cachedMetadata Cached metadata from the tree
10+ * @param {@ui5/project/build/cache/index/HashTree~ResourceMetadata } cachedMetadata
11+ * Cached metadata from the tree
2912 * @param {number } [indexTimestamp] Timestamp when the tree state was created
3013 * @returns {Promise<boolean> } True if resource content is unchanged
3114 * @throws {Error } If resource or metadata is undefined
@@ -34,14 +17,12 @@ export async function isResourceUnchanged(resource, cachedMetadata, indexTimesta
3417 if ( ! resource || ! cachedMetadata ) {
3518 throw new Error ( "Cannot compare undefined resources or metadata" ) ;
3619 }
37- if ( PERF_TRACKING ) perfCounters . calls ++ ;
3820
3921 // Size mismatch indicates a definite content change. Required before any
4022 // "unchanged" decision because mtime preservation (cp -p, tar -x, rsync -t,
4123 // atomic rename) does not imply content unchanged.
4224 const currentSize = await resource . getSize ( ) ;
4325 if ( currentSize !== cachedMetadata . size ) {
44- if ( PERF_TRACKING ) perfCounters . sizeMismatch ++ ;
4526 return false ;
4627 }
4728
@@ -54,27 +35,23 @@ export async function isResourceUnchanged(resource, cachedMetadata, indexTimesta
5435 const inodeMismatch =
5536 cachedMetadata . inode !== undefined && currentInode !== undefined &&
5637 currentInode !== cachedMetadata . inode ;
57- if ( inodeMismatch && PERF_TRACKING ) perfCounters . inodeMismatch ++ ;
5838
5939 // mtime + size both match and the file has not been replaced → unchanged,
6040 // unless we are in the racy-git window (mtime === indexTimestamp), where
6141 // content may have changed during indexing without mtime moving.
6242 const currentLastModified = resource . getLastModified ( ) ;
6343 if ( ! inodeMismatch && currentLastModified === cachedMetadata . lastModified ) {
6444 if ( indexTimestamp && currentLastModified !== indexTimestamp ) {
65- if ( PERF_TRACKING ) perfCounters . shortCircuitTrue ++ ;
6645 return true ;
6746 }
6847 // Race condition possible — fall through to integrity check
6948 }
7049
7150 // mtime differs, file was replaced, or racy window — verify content.
72- if ( PERF_TRACKING ) perfCounters . integrityFallback ++ ;
7351 const currentIntegrity = await resource . getIntegrity ( ) ;
7452 return currentIntegrity === cachedMetadata . integrity ;
7553}
7654
77-
7855/**
7956 * Creates an index of resource metadata from an array of resources
8057 *
@@ -98,40 +75,3 @@ export async function createResourceIndex(resources) {
9875 } ;
9976 } ) ) ;
10077}
101-
102- /**
103- * Returns the first truthy value from an array of promises
104- *
105- * This function evaluates all promises in parallel and returns immediately
106- * when the first truthy value is found. If all promises resolve to falsy
107- * values, null is returned.
108- *
109- * @param {Promise[] } promises Array of promises to evaluate
110- * @returns {Promise<*> } The first truthy resolved value or null if all are falsy
111- */
112- export async function firstTruthy ( promises ) {
113- return new Promise ( ( resolve , reject ) => {
114- let completed = 0 ;
115- const total = promises . length ;
116-
117- if ( total === 0 ) {
118- resolve ( null ) ;
119- return ;
120- }
121-
122- promises . forEach ( ( promise ) => {
123- Promise . resolve ( promise )
124- . then ( ( value ) => {
125- if ( value ) {
126- resolve ( value ) ;
127- } else {
128- completed ++ ;
129- if ( completed === total ) {
130- resolve ( null ) ;
131- }
132- }
133- } )
134- . catch ( reject ) ;
135- } ) ;
136- } ) ;
137- }
0 commit comments