Skip to content

Commit

Permalink
Removes unnecesary comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidJGapCR committed Oct 13, 2023
1 parent b2d33ef commit 42e6039
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { AuthorizationDocument } from '../model/AuthorizationDocument';

export const DOCUMENT_COLLECTION_NAME = 'documents';
export const AUTHORIZATION_COLLECTION_NAME = 'authorizations';

// RND-644
export const CONCURRENCY_COLLECTION_NAME = 'concurrency';

let singletonClient: MongoClient | null = null;
Expand Down Expand Up @@ -50,7 +48,7 @@ export async function getNewClient(): Promise<MongoClient> {
const concurrencyCollection: Collection<ConcurrencyDocument> = newClient
.db(databaseName)
.collection(CONCURRENCY_COLLECTION_NAME);
await concurrencyCollection.createIndex({ meadowlarkId: 1, documentUuid: 1 }, { unique: true }); // RND-644
await concurrencyCollection.createIndex({ meadowlarkId: 1, documentUuid: 1 }, { unique: true });

return newClient;
} catch (e) {
Expand Down Expand Up @@ -98,7 +96,7 @@ export function getDocumentCollection(client: MongoClient): Collection<Meadowlar
export function getAuthorizationCollection(client: MongoClient): Collection<AuthorizationDocument> {
return client.db(Config.get<string>('MEADOWLARK_DATABASE_NAME')).collection(AUTHORIZATION_COLLECTION_NAME);
}
// RND-644

export function getConcurrencyCollection(client: MongoClient): Collection<ConcurrencyDocument> {
return client.db(Config.get<string>('MEADOWLARK_DATABASE_NAME')).collection(CONCURRENCY_COLLECTION_NAME);
}
Expand Down Expand Up @@ -150,7 +148,7 @@ export const asUpsert = (session: ClientSession): ReplaceOptions => ({ upsert: t
export const limitFive = (session: ClientSession): FindOptions => ({ limit: 5, session });

/**
* Alternative to writeLockReferencedDocuments function. RND-644
* Alternative to writeLockReferencedDocuments function.
* */
export async function insertMeadowlarkIdOnConcurrencyCollection(
concurrencyCollection: Collection<ConcurrencyDocument>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function checkForReferencesToDocument(
export async function deleteDocumentByMeadowlarkIdTransaction(
{ documentUuid, validateNoReferencesToDocument, traceId }: DeleteRequest,
mongoCollection: Collection<MeadowlarkDocument>,
concurrencyCollection: Collection<ConcurrencyDocument>, // RND-644
concurrencyCollection: Collection<ConcurrencyDocument>,
session: ClientSession,
): Promise<DeleteResult> {
if (validateNoReferencesToDocument) {
Expand All @@ -109,11 +109,11 @@ export async function deleteDocumentByMeadowlarkIdTransaction(
},
];

await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644
await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments);

const { acknowledged, deletedCount } = await mongoCollection.deleteOne({ documentUuid }, { session });

await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644
await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments);

if (!acknowledged) {
const msg =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async function updateAllowingIdentityChange(
document: MeadowlarkDocument,
updateRequest: UpdateRequest,
mongoCollection: Collection<MeadowlarkDocument>,
concurrencyCollection: Collection<ConcurrencyDocument>, // RND-644
concurrencyCollection: Collection<ConcurrencyDocument>,
session: ClientSession,
): Promise<UpdateResult> {
const { documentUuid, resourceInfo, traceId, security } = updateRequest;
Expand All @@ -165,7 +165,7 @@ async function updateAllowingIdentityChange(
}));
concurrencyDocuments.push({ meadowlarkId: updateRequest.meadowlarkId, documentUuid: updateRequest.documentUuid });

await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644
await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments);

// Optimize happy path by trying a replacement update, which will succeed if there is no identity change
const tryUpdateByReplacementResult: UpdateResult | null = await tryUpdateByReplacement(
Expand All @@ -175,7 +175,7 @@ async function updateAllowingIdentityChange(
session,
);

await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644
await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments);

if (tryUpdateByReplacementResult != null) {
// Ensure referenced documents are not modified in other transactions
Expand Down Expand Up @@ -251,7 +251,7 @@ async function updateDisallowingIdentityChange(
document: MeadowlarkDocument,
updateRequest: UpdateRequest,
mongoCollection: Collection<MeadowlarkDocument>,
concurrencyCollection: Collection<ConcurrencyDocument>, // RND-644
concurrencyCollection: Collection<ConcurrencyDocument>,
session: ClientSession,
): Promise<UpdateResult> {
// Perform the document update
Expand All @@ -269,7 +269,7 @@ async function updateDisallowingIdentityChange(
}));
concurrencyDocuments.push({ meadowlarkId: updateRequest.meadowlarkId, documentUuid: updateRequest.documentUuid });

await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644
await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments);

const tryUpdateByReplacementResult: UpdateResult | null = await tryUpdateByReplacement(
document,
Expand All @@ -278,7 +278,7 @@ async function updateDisallowingIdentityChange(
session,
);

await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644
await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments);

if (tryUpdateByReplacementResult != null) return tryUpdateByReplacementResult;

Expand Down Expand Up @@ -354,7 +354,7 @@ async function checkForInvalidReferences(
async function updateDocumentByDocumentUuidTransaction(
updateRequest: UpdateRequest,
mongoCollection: Collection<MeadowlarkDocument>,
concurrencyCollection: Collection<ConcurrencyDocument>, // RND-644
concurrencyCollection: Collection<ConcurrencyDocument>,
session: ClientSession,
): Promise<UpdateResult> {
const { meadowlarkId, documentUuid, resourceInfo, documentInfo, edfiDoc, validateDocumentReferencesExist, security } =
Expand All @@ -381,7 +381,7 @@ async function updateDocumentByDocumentUuidTransaction(
lastModifiedAt: documentInfo.requestTimestamp,
});
if (resourceInfo.allowIdentityUpdates) {
return updateAllowingIdentityChange(document, updateRequest, mongoCollection, concurrencyCollection, session); // RND-644
return updateAllowingIdentityChange(document, updateRequest, mongoCollection, concurrencyCollection, session);
}
return updateDisallowingIdentityChange(document, updateRequest, mongoCollection, concurrencyCollection, session);
}
Expand All @@ -398,7 +398,7 @@ export async function updateDocumentByDocumentUuid(
Logger.info(`${moduleName}.updateDocumentByDocumentUuid ${documentUuid}`, traceId);

const mongoCollection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const concurrencyCollection: Collection<ConcurrencyDocument> = getConcurrencyCollection(client); // RND-644
const concurrencyCollection: Collection<ConcurrencyDocument> = getConcurrencyCollection(client);
const session: ClientSession = client.startSession();
let updateResult: UpdateResult = { response: 'UNKNOWN_FAILURE' };

Expand All @@ -411,7 +411,7 @@ export async function updateDocumentByDocumentUuid(
updateResult = await updateDocumentByDocumentUuidTransaction(
updateRequest,
mongoCollection,
concurrencyCollection, // RND-644
concurrencyCollection,
session,
);
if (updateResult.response !== 'UPDATE_SUCCESS') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const moduleName: string = 'mongodb.repository.Upsert';
export async function upsertDocumentTransaction(
{ resourceInfo, documentInfo, meadowlarkId, edfiDoc, validateDocumentReferencesExist, traceId, security }: UpsertRequest,
mongoCollection: Collection<MeadowlarkDocument>,
concurrencyCollection: Collection<ConcurrencyDocument>, // RND-644
concurrencyCollection: Collection<ConcurrencyDocument>,
session: ClientSession,
documentFromUpdate?: MeadowlarkDocument,
): Promise<UpsertResult> {
Expand Down Expand Up @@ -148,7 +148,7 @@ export async function upsertDocumentTransaction(
}));
concurrencyDocuments.push({ meadowlarkId, documentUuid });

await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644
await insertMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments);
// Perform the document upsert
Logger.debug(`${moduleName}.upsertDocumentTransaction Upserting document uuid ${documentUuid}`, traceId);

Expand All @@ -158,7 +158,7 @@ export async function upsertDocumentTransaction(
asUpsert(session),
);

await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments); // RND-644
await deleteMeadowlarkIdOnConcurrencyCollection(concurrencyCollection, concurrencyDocuments);

if (!acknowledged) {
const msg =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ describe('given a delete concurrent with an insert referencing the to-be-deleted
// **** The insert of AcademicWeek document should have been successful
expect(upsertedCount).toBe(1);

// RND-644
// Adds the academic week and the, to be updated, school to the concurrency collection.
const concurrencyDocumentsAcademicWeek: ConcurrencyDocument[] = [];
concurrencyDocumentsAcademicWeek.push({ meadowlarkId: academicWeekMeadowlarkId, documentUuid });
Expand All @@ -212,7 +211,6 @@ describe('given a delete concurrent with an insert referencing the to-be-deleted
// ----
await upsertSession.commitTransaction();

// RND-644
const concurrencyDocumentsSchool: ConcurrencyDocument[] = [];
concurrencyDocumentsSchool.push({
meadowlarkId: schoolMeadowlarkId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ describe('given an upsert (update) concurrent with an insert referencing the to-
// **** The insert of AcademicWeek document should have been successful
expect(upsertedCount).toBe(1);

// RND-644
// Adds the academic week and the, to be updated, school to the concurrency collection.
const concurrencyDocumentsAcademicWeek: ConcurrencyDocument[] = [];
concurrencyDocumentsAcademicWeek.push({ meadowlarkId: academicWeekMeadowlarkId, documentUuid });
Expand All @@ -213,7 +212,6 @@ describe('given an upsert (update) concurrent with an insert referencing the to-
// ----
await upsertSession.commitTransaction();

// RND-644
const concurrencyDocumentsSchool: ConcurrencyDocument[] = [];
concurrencyDocumentsSchool.push({
meadowlarkId: schoolMeadowlarkId,
Expand Down

0 comments on commit 42e6039

Please sign in to comment.