Skip to content

Instantly share code, notes, and snippets.

@noam-honig
Last active September 11, 2024 12:59
Show Gist options
  • Save noam-honig/cb8be45538cedadda9eb29e8bafe9b83 to your computer and use it in GitHub Desktop.
Save noam-honig/cb8be45538cedadda9eb29e8bafe9b83 to your computer and use it in GitHub Desktop.
DataProvider wrapper that documents number of returned rows and query duration
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