Skip to content

Fix key name#37

Merged
eldadfux merged 3 commits intomainfrom
fix-key-name
Jul 19, 2021
Merged

Fix key name#37
eldadfux merged 3 commits intomainfrom
fix-key-name

Conversation

@eldadfux
Copy link
Copy Markdown
Member

Changed generic key name to key instead of text

Copy link
Copy Markdown
Contributor

@kodumbeats kodumbeats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question :)

Comment thread tests/Database/Validator/QueriesTest.php Outdated
@eldadfux eldadfux merged commit 5a7a696 into main Jul 19, 2021
@abnegate abnegate deleted the fix-key-name branch November 23, 2023 01:53
premtsd-code added a commit that referenced this pull request Apr 13, 2026
Previously the Database orchestrator carried a pre-fetch + chunk-filter
pass to compensate for Mongo's plain upsert() returning matched +
upserted combined ('n') — without that compensation, $modified would
over-count the number of pre-existing docs in the batch.

This pushes the responsibility into the adapter, where it belongs:
- composer bump to utopia-php/mongo dev-upsert-return-upserted-count
  (PR #37, adds Client::upsertWithCounts() returning matched/modified/
  upserted[] separately)
- Mongo adapter calls upsertWithCounts() and maps the response's
  upserted[].index entries back to the originating Document objects,
  returning ONLY the actually-inserted docs (race-safe)
- Database::createDocuments drops $preExistingIds pre-fetch and the
  chunk filter; the adapter is now responsible for accurate counts

Net effect on Database.php: ~17 lines removed. Net effect on Mongo.php:
~80 lines net deletion (replaced the inline pre-filter with a single
upsertWithCounts call + index mapping).
premtsd-code added a commit that referenced this pull request Apr 13, 2026
The SQL adapter previously carried a pre-filter SELECT plus a _createdAt
reconciliation pass to compensate for INSERT IGNORE not telling us which
rows were actually inserted vs skipped. The Mongo adapter pulled the same
trick via Client::upsertWithCounts() (mongo PR #37). Both layers were
solving the same problem twice.

Move the pre-filter back to Database::createDocuments where it ran
originally, and let each adapter's INSERT IGNORE / ON CONFLICT DO NOTHING
/ upsert+\$setOnInsert serve only as a race-safety net. The adapter just
returns its input as the inserted set.

- Database.php: restore \$preExistingIds pre-fetch + chunk filter
- SQL.php: drop pre-filter, drop _createdAt reconciliation, drop
  buildUidTenantLookup helper (-173 lines)
- Mongo.php: revert to plain Client::upsert(), return input docs
  (withTransaction skipDuplicates bypass stays — still needed to avoid
  WriteConflict under snapshot isolation)
- composer.json/lock: back to stable utopia-php/mongo 1.*

Trade-off: in the race window between the orchestrator's pre-fetch
SELECT and the adapter INSERT, \$modified over-reports by N and onNext
fires for N skipped docs. Common case stays correct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants