Skip to content

Commit

Permalink
TODO's added for optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
TimCsaky committed Aug 11, 2023
1 parent 671e741 commit 425ec0d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
27 changes: 14 additions & 13 deletions app/src/services/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,22 @@ const service = {


/**
* @function dissociateMetadata
* Dissociates all provided metadata from a version
* @param {string} versionId The uuid id column from version table
* @param {object[]} [metadata=undefined] array of metadata (eg: [{ key: 'a', value: '1'}, {key: 'B', value: ''}])
* @param {object} [etrx=undefined] An optional Objection Transaction object
* @returns {Promise<number>} The result of running the delete operation (number of rows deleted)
* @throws The error encountered upon db transaction failure
*/
* @function dissociateMetadata
* Dissociates all provided metadata from a version
* @param {string} versionId The uuid id column from version table
* @param {object[]} [metadata=undefined] array of metadata (eg: [{ key: 'a', value: '1'}, {key: 'B', value: ''}])
* @param {object} [etrx=undefined] An optional Objection Transaction object
* @returns {Promise<number>} The result of running the delete operation (number of rows deleted)
* @throws The error encountered upon db transaction failure
*/
dissociateMetadata: async (versionId, metadata = undefined, etrx = undefined) => {
let trx;
try {
trx = etrx ? etrx : await Metadata.startTransaction();
let response = 0;

// TODO: consider doing one bulk delete query instead of using forEach
// eg: get id's of provided metadata records and do whereIn().delete()
metadata.forEach(async meta => {
// match on key
const params = { 'metadata.key': meta.key };
Expand Down Expand Up @@ -166,10 +168,10 @@ const service = {
/**
* @function fetchMetadataForObject
* Fetch metadata for specific objects, optionally scoped to a user's object/bucket READ permission
* @param {string[]} [params.bucketIds] An array of uuids representing buckets
* @param {string[]} [params.bucketIds] An array of uuids representing buckets
* @param {string[]} params.objId An array of uuids representing the object
* @param {object} [params.metadata] Optional object of metadata key/value pairs
* @param {string} [params.userId] Optional uuid representing a user
* @param {string} [params.userId] Optional uuid representing a user
* @returns {Promise<object[]>} The result of running the find operation
*/
fetchMetadataForObject: (params) => {
Expand Down Expand Up @@ -258,7 +260,6 @@ const service = {
* @returns {Promise<number>} The result of running the delete operation (number of rows deleted)
* @throws The error encountered upon db transaction failure
*/
// TODO: check if deleting a version will prune orphan metadata records (sister table)
pruneOrphanedMetadata: async (etrx = undefined) => {
let trx;
try {
Expand All @@ -284,9 +285,9 @@ const service = {

/**
* @function searchMetadata
* Search and filter for specific metadata keys
* Search and filter for specific metadata keys
* @param {object} [params.metadata] Optional object of metadata keys to filter on
* @param {string} [params.userId] Optional uuid representing a user
* @param {string} [params.userId] Optional uuid representing a user
* @returns {Promise<object[]>} The result of running the find operation
*/
searchMetadata: (params) => {
Expand Down
14 changes: 11 additions & 3 deletions app/src/services/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const service = {
storageService.headObject({ filePath: path, bucketId: bucketId })
.catch((e) => {
// return true if object is soft-deleted in S3
if(e.$response.headers['x-amz-delete-marker']){
if (e.$response.headers['x-amz-delete-marker']) {
return true; // it's a 'delete-marker'
}
})
Expand All @@ -134,7 +134,7 @@ const service = {
let objId = uuidv4();

// IF not a delete-marker,
if(typeof s3Object === 'object'){
if (typeof s3Object === 'object') {
// get a COMS uuid using the 'coms-id' tag on object in S3 (if managed by another COMS instance), otherwise add it
// we can do this here in case not syncing tags later in full mode
// note, putObjectTagging does a replace in S3 so we concat with existing tags
Expand All @@ -146,6 +146,14 @@ const service = {
await storageService.putObjectTagging({ filePath: path, bucketId: bucketId, tags: s3Obj.TagSet.concat([{ Key: 'coms-id', Value: objId }]) });
}
}
/**
* TODO: if object wass soft-deleted in S3, must check previous version for coms-id tag
* else {
* if s3Object === 'dm'...
* list versions..
* forEach, look for coms-id tag
* }
*/

// create object in COMS db
response = await objectService.create({
Expand Down Expand Up @@ -320,7 +328,7 @@ const service = {
* @returns {object[]} array of synced tags that exist in COMS and S3 eg:
* [ <Tag>, <Tag> ]
*/
syncTags: async ({ version, path, bucketId=undefined, objectId, userId }, etrx = undefined) => {
syncTags: async ({ version, path, bucketId = undefined, objectId, userId }, etrx = undefined) => {
let trx;
try {
trx = etrx ? etrx : await ObjectModel.startTransaction();
Expand Down
1 change: 1 addition & 0 deletions app/src/services/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ const service = {
* @returns {object} Version model of updated version in db
*/
updateIsLatest: async ({ id, objectId, isLatest }, etrx = undefined) => {
// TODO: consider having accepting a `userId` argument for version.updatedBy when a version becomes 'latest'
let trx;
try {
trx = etrx ? etrx : await Version.startTransaction();
Expand Down

0 comments on commit 425ec0d

Please sign in to comment.