-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cache in getGoogleDriveObject, improved fixParents #10588
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
21bb37c
Add cache in getGoogleDriveObject, improved fixParents
tdraier 72c5a3c
use dedicated key type
tdraier b6210af
Add comment, use dry run
tdraier 7a3b679
Update spreadsheets
tdraier e9d8693
use object for params:
tdraier b161117
clean up and docment
tdraier 3bdcbe0
Merge branch 'main' into thomas/fix-parents-2
tdraier 2d89896
fix parent update
tdraier 668bf2e
handle out-of-sync files
tdraier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { cacheWithRedis } from "@dust-tt/types"; | ||
import type { OAuth2Client } from "googleapis-common"; | ||
import type { GaxiosError } from "googleapis-common"; | ||
|
||
|
@@ -9,7 +10,12 @@ import { ExternalOAuthTokenError } from "@connectors/lib/error"; | |
import type { GoogleDriveObjectType } from "@connectors/types/google_drive"; | ||
import { FILE_ATTRIBUTES_TO_FETCH } from "@connectors/types/google_drive"; | ||
|
||
export async function getGoogleDriveObject( | ||
interface CacheKey { | ||
connectorId: number; | ||
ts: string | number; | ||
} | ||
|
||
async function _getGoogleDriveObject( | ||
authCredentials: OAuth2Client, | ||
driveObjectId: string | ||
): Promise<GoogleDriveObjectType | null> { | ||
|
@@ -39,3 +45,25 @@ export async function getGoogleDriveObject( | |
throw e; | ||
} | ||
} | ||
|
||
const cachedGetGoogleDriveObject = cacheWithRedis< | ||
GoogleDriveObjectType | null, | ||
[OAuth2Client, string, CacheKey] | ||
>( | ||
_getGoogleDriveObject, | ||
(_, driveObjectId, { connectorId, ts }) => { | ||
return `${connectorId}:${driveObjectId}:${ts}`; | ||
}, | ||
60 * 10 * 1000 | ||
); | ||
|
||
export async function getGoogleDriveObject( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: here what I had suggested was to move to an object argument, so we see in the calls that we are providing cache keys |
||
authCredentials: OAuth2Client, | ||
driveObjectId: string, | ||
cacheKey?: CacheKey | ||
): Promise<GoogleDriveObjectType | null> { | ||
if (cacheKey) { | ||
return cachedGetGoogleDriveObject(authCredentials, driveObjectId, cacheKey); | ||
} | ||
return _getGoogleDriveObject(authCredentials, driveObjectId); | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this function supposed to be removed after?
I assume yes; let's add a
TODO(nodes-core) clean up after project
(if not, we need to explain in detail what this does in a comment and why we had to resort to such extremities)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe after we just remove the call in activities/garbage collector (but in that case would still need to explain what we do & why in a com)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep it, at least for cli. For GC if everything is ok we can at some point remove it too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched it to dry run when running from the garbage collect, this will just log if we have inconsistent parent ids (not checking from google to avoid load)
Still the cli may be necessary until we're sure everything is fixed in the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we keep it then we need a good comment here because the function doesn't speak for itself