Skip to content

Commit 3988fa7

Browse files
committed
1 parent 6d4e91d commit 3988fa7

File tree

3 files changed

+2
-29
lines changed

3 files changed

+2
-29
lines changed

spec/AuthDataUniqueIndex.spec.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,19 @@ describe('AuthData Unique Index', () => {
137137
config.database.options.databaseOptions = originalOptions;
138138
});
139139

140-
it('should handle calling ensureAuthDataUniqueness multiple times via cache', async () => {
140+
it('should handle calling ensureAuthDataUniqueness multiple times (idempotent)', async () => {
141141
const config = Config.get('test');
142142
const adapter = config.database.adapter;
143143

144-
// First call creates the index
144+
// Both calls should succeed (index creation is idempotent)
145145
await adapter.ensureAuthDataUniqueness('fakeAuthProvider');
146-
// Second call should be a cache hit (no DB call)
147146
await adapter.ensureAuthDataUniqueness('fakeAuthProvider');
148-
expect(adapter._authDataUniqueIndexes.has('fakeAuthProvider')).toBe(true);
149147
});
150148

151149
it('should log warning when index creation fails due to existing duplicates', async () => {
152150
const config = Config.get('test');
153151
const adapter = config.database.adapter;
154152

155-
// Clear cache to force index creation attempt
156-
if (adapter._authDataUniqueIndexes) {
157-
adapter._authDataUniqueIndexes.clear();
158-
}
159-
160153
// Spy on the adapter to simulate a duplicate value error
161154
spyOn(adapter, 'ensureAuthDataUniqueness').and.callFake(() => {
162155
return Promise.reject(

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -844,22 +844,13 @@ export class MongoStorageAdapter implements StorageAdapter {
844844
// Creates a unique sparse index on _auth_data_<provider>.id to prevent
845845
// race conditions during concurrent signups with the same authData.
846846
ensureAuthDataUniqueness(provider: string) {
847-
if (!this._authDataUniqueIndexes) {
848-
this._authDataUniqueIndexes = new Set();
849-
}
850-
if (this._authDataUniqueIndexes.has(provider)) {
851-
return Promise.resolve();
852-
}
853847
return this._adaptiveCollection('_User')
854848
.then(collection =>
855849
collection._mongoCollection.createIndex(
856850
{ [`_auth_data_${provider}.id`]: 1 },
857851
{ unique: true, sparse: true, background: true, name: `_auth_data_${provider}_id` }
858852
)
859853
)
860-
.then(() => {
861-
this._authDataUniqueIndexes.add(provider);
862-
})
863854
.catch(error => {
864855
if (error.code === 11000) {
865856
throw new Parse.Error(
@@ -869,7 +860,6 @@ export class MongoStorageAdapter implements StorageAdapter {
869860
}
870861
// Ignore "index already exists with same name" or "index already exists with different options"
871862
if (error.code === 85 || error.code === 86) {
872-
this._authDataUniqueIndexes.add(provider);
873863
return;
874864
}
875865
throw error;

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,9 +1223,6 @@ export class PostgresStorageAdapter implements StorageAdapter {
12231223
const now = new Date().getTime();
12241224
const helpers = this._pgp.helpers;
12251225
debug('deleteAllClasses');
1226-
if (this._authDataUniqueIndexes) {
1227-
this._authDataUniqueIndexes.clear();
1228-
}
12291226
if (this._client?.$pool.ended) {
12301227
return;
12311228
}
@@ -2087,12 +2084,6 @@ export class PostgresStorageAdapter implements StorageAdapter {
20872084
// Creates a unique index on authData-><provider>->>'id' to prevent
20882085
// race conditions during concurrent signups with the same authData.
20892086
async ensureAuthDataUniqueness(provider: string) {
2090-
if (!this._authDataUniqueIndexes) {
2091-
this._authDataUniqueIndexes = new Set();
2092-
}
2093-
if (this._authDataUniqueIndexes.has(provider)) {
2094-
return;
2095-
}
20962087
const indexName = `_User_unique_authData_${provider}_id`;
20972088
const qs = `CREATE UNIQUE INDEX IF NOT EXISTS $1:name ON "_User" (("authData"->$2::text->>'id')) WHERE "authData"->$2::text->>'id' IS NOT NULL`;
20982089
await this._client.none(qs, [indexName, provider]).catch(error => {
@@ -2113,7 +2104,6 @@ export class PostgresStorageAdapter implements StorageAdapter {
21132104
throw error;
21142105
}
21152106
});
2116-
this._authDataUniqueIndexes.add(provider);
21172107
}
21182108
21192109
// Executes a count.

0 commit comments

Comments
 (0)