-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: handle excessively long URLs by performing local equality checks. ref #7986 #8432
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
Open
len360
wants to merge
2
commits into
pubkey:master
Choose a base branch
from
len360:bugfix/issue-7986
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+79
−84
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,63 +1,3 @@ | ||
| import { SupabaseClient } from '@supabase/supabase-js'; | ||
| import { RxDocumentData, RxJsonSchema, WithDeleted } from '../../types'; | ||
|
|
||
| export const POSTGRES_INSERT_CONFLICT_CODE = "23505"; | ||
| export const DEFAULT_MODIFIED_FIELD = '_modified'; | ||
| export const DEFAULT_DELETED_FIELD = '_deleted'; | ||
|
|
||
|
|
||
| export function addDocEqualityToQuery<RxDocType>( | ||
| jsonSchema: RxJsonSchema<RxDocumentData<RxDocType>>, | ||
| deletedField: string, | ||
| modifiedField: string, | ||
| doc: WithDeleted<RxDocType>, | ||
| query: any | ||
| ) { | ||
| const ignoreKeys = new Set([ | ||
| modifiedField, | ||
| deletedField, | ||
| '_meta', | ||
| '_attachments', | ||
| '_rev' | ||
| ]); | ||
|
|
||
| for (const key of Object.keys(doc)) { | ||
| if ( | ||
| ignoreKeys.has(key) | ||
| ) { | ||
| continue; | ||
| } | ||
|
|
||
| const v = (doc as any)[key]; | ||
| const type = typeof v; | ||
|
|
||
| if (type === "string" || type === "number") { | ||
| query = query.eq(key, v); | ||
| } else if (type === "boolean" || v === null) { | ||
| query = query.is(key, v); | ||
| } else if (type === 'undefined') { | ||
| query = query.is(key, null); | ||
| } else { | ||
| throw new Error(`unknown how to handle type: ${type}`) | ||
| } | ||
| } | ||
|
|
||
| const schemaProps: Record<string, any> = jsonSchema.properties; | ||
| for (const key of Object.keys(schemaProps)) { | ||
| if ( | ||
| ignoreKeys.has(key) || | ||
| Object.hasOwn(doc, key) | ||
| ) { | ||
| continue; | ||
| } | ||
| query = query.is(key, null); | ||
| } | ||
|
|
||
| query = query.eq(deletedField, doc._deleted); | ||
| if (schemaProps[modifiedField]) { | ||
| query = query.eq(modifiedField, (doc as any)[modifiedField]); | ||
| } | ||
|
|
||
|
|
||
| return query; | ||
| } | ||
| export const DEFAULT_DELETED_FIELD = '_deleted'; |
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
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
Oops, something went wrong.
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.
By fetching here first it is not inside of one transaction anymore. What happens if someone else changes the document on the server after we fetch docOnServer and before sending the new one to the server?
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.
In fact, this implementation seems problematic. If someone modifies the data in the database while another user is fetching it, the last user to write will overwrite the previous changes without any conflict handling.
Another way to address the issue of overly long URLs would be to add a hash property to the object. This "hash" could be included in the URL alongside the identifier, allowing the update to be performed in a single transaction while also helping detect potential conflicts.
What do you think about this approach?