Created
April 20, 2022 01:48
-
-
Save avivl/76f6df01227351f7d17faa54d6deef43 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var LRUCache = require('mnemonist/lru-cache'); | |
| var getJobPostCache = new LRUCache(1000); | |
| export const getJobPostJson = async (jobId: string) => { | |
| const job = getJobPostCache.get(jobId) | |
| if (job !== undefined) { | |
| return ({ | |
| job, | |
| isJobBelongsToThisUser: true | |
| }) | |
| } | |
| return _getJobPost(jobId).then((snapshot: any) => { | |
| const docs = snapshot.docs.map((doc: { data: () => any; }) => doc.data()); | |
| getJobPostCache.set(jobId, docs ) | |
| return ( | |
| { job: docs, isJobBelongsToThisUser: true } | |
| ); | |
| }).catch(error => { | |
| logger.error(error) | |
| return ({ | |
| status: "error", | |
| message: error.message, | |
| }) | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Comments from a stranger on the internet :) .
Lines #1, #2: Use
const.Line #4: No need to declare the function as
asyncif you're not usingawaitinside it.Line #6:
if (job)will do.Line #9 - does the function ever return an
isJobBelongsToUser: false?Line #12: I'd avoid using an explicit
any, and linters can be configured to kick you in the shin if you do it. It's a style decision, though, with a tradeoff of type safety vs. development speed.Line #20: this means
getJobPostJsonmay return two completely different objects, and whoever calls the function needs to somehow figure out which object type is it.Consider either re-throwing or add a status field to the 'vanilla' JSON.