Last active
September 11, 2024 12:59
-
-
Save noam-honig/cb8be45538cedadda9eb29e8bafe9b83 to your computer and use it in GitHub Desktop.
DataProvider wrapper that documents number of returned rows and query duration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return new Proxy(db, { | |
get(target, prop) { | |
if (prop == 'getEntityDataProvider') { | |
return (meta: EntityMetadata) => { | |
return new Proxy(db.getEntityDataProvider(meta), { | |
get(target, prop) { | |
if (prop == 'find') { | |
return async (options: EntityDataProviderFindOptions) => { | |
const start = performance.now(); | |
const result = await target.find(options); | |
const duration = performance.now() - start; | |
// if (result.length > 101 || duration > 1) | |
console.log( | |
'LongRequest:', | |
meta.key, | |
options?.limit, | |
'=>', | |
result.length, | |
duration.toFixed(2), | |
options.where?.toJson(), | |
//@ts-ignore | |
remult.context.request.url | |
); | |
return result; | |
}; | |
} | |
//@ts-ignore | |
return target[prop as any]; | |
}, | |
}); | |
}; | |
} | |
//@ts-ignore | |
else return target[prop as any]; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment