Skip to content
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

release 1.6.15 #949

Merged
merged 14 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esversion": 11
}
71 changes: 34 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cadt",
"version": "1.6.14",
"version": "1.6.15",
"_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2",
"private": true,
"bin": "build/server.js",
Expand Down Expand Up @@ -75,7 +75,7 @@

"mocha": "^10.2.0",
"semver": "^7.5.4",
"sinon": "^16.0.0",
"sinon": "^16.1.0",
"socket.io-client": "^4.7.2",
"standard-version": "^9.5.0",
"supertest": "^6.3.3"
Expand Down
10 changes: 9 additions & 1 deletion src/controllers/organization.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,15 @@ export const getMetaData = async (req, res) => {
where: { orgUid: req.query.orgUid },
});

return res.json(JSON.parse(organization.metadata));
const rawMetadata = JSON.parse(organization.metadata);
const cleanedMetadata = {};

for (const [key, value] of Object.entries(rawMetadata)) {
const newKey = key.startsWith('meta_') ? key.substring(5) : key;
cleanedMetadata[newKey] = value;
}

return res.json(cleanedMetadata);
} catch (error) {
res.status(400).json({
message: 'Error getting metadata for organization',
Expand Down
18 changes: 9 additions & 9 deletions src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,17 @@ const getStoreData = async (storeId, rootHash) => {
}
return data;
}

logger.error(
`FAILED GETTING STORE DATA FOR ${storeId}: ${JSON.stringify(data)}`,
);
} catch (error) {
logger.info(
`Unable to find store data for ${storeId} at root ${
rootHash || 'latest'
}`,
);
logger.error(error.message);
return false;
}
}
Expand All @@ -330,20 +335,15 @@ const getRoot = async (storeId, ignoreEmptyStore = false) => {
.timeout(timeout)
.send({ id: storeId });

const data = response.body;
const { confirmed, hash } = response.body;

if (
(data.confirmed && !ignoreEmptyStore) ||
(data.confirmed &&
ignoreEmptyStore &&
!data.hash.includes('0x00000000000'))
) {
return data;
if (confirmed && (!ignoreEmptyStore || !hash.includes('0x00000000000'))) {
return response.body;
}

return false;
} catch (error) {
logger.error(error);
logger.error(error.message);
return false;
}
};
Expand Down
81 changes: 58 additions & 23 deletions src/datalayer/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,39 @@ const getRootDiff = (storeId, root1, root2) => {
}
};

const getStoreData = async (storeId, callback, onFail, retry = 0) => {
logger.info(`Getting store data, retry: ${retry}`);
if (retry <= 10) {
const encodedData = await dataLayer.getStoreData(storeId);
if (_.isEmpty(encodedData?.keys_values)) {
await new Promise((resolve) => setTimeout(() => resolve(), 120000));
return getStoreData(storeId, callback, onFail, retry + 1);
} else {
callback(decodeDataLayerResponse(encodedData));
/**
* Fetches store data and invokes either a callback or an error handler.
*
* @param {string} storeId - The ID of the store to fetch data for.
* @param {Function} callback - Function to call on successful data retrieval.
* @param {Function} onFail - Function to call when data retrieval fails.
* @param {number} retry - Number of retry attempts.
*/
const getStoreData = async (storeId, callback, onFail, rootHash, retry = 0) => {
const MAX_RETRIES = 50;
const RETRY_DELAY = 120000;

try {
logger.info(`Getting store data, retry: ${retry}`);

if (retry > MAX_RETRIES) {
return onFail(`Max retries exceeded for store ${storeId}`);
}
} else {
onFail();

const encodedData = await dataLayer.getStoreData(storeId, rootHash);

if (!encodedData || _.isEmpty(encodedData?.keys_values)) {
logger.debug(`No data found for store ${storeId}, retrying...`);
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
return getStoreData(storeId, callback, onFail, rootHash, retry + 1);
}

const decodedData = decodeDataLayerResponse(encodedData);

callback(decodedData);
} catch (error) {
logger.error(error.message);
onFail(error.message);
}
};

Expand All @@ -315,18 +336,32 @@ const getCurrentStoreData = async (storeId) => {
}
};

const getStoreIfUpdated = async (
storeId,
lastRootHash,
onUpdate,
callback,
onFail,
) => {
const rootResponse = await dataLayer.getRoot(storeId);
if (rootResponse.confirmed && rootResponse.hash !== lastRootHash) {
logger.debug(`Updating orgUid ${storeId} with hash ${rootResponse.hash}`);
onUpdate(rootResponse.hash);
await getStoreData(storeId, callback, onFail);
/**
* Checks if the store data has been updated and triggers the appropriate callbacks.
*
* @param {string} storeId - The ID of the store to check.
* @param {string} lastRootHash - The last known root hash for comparison.
* @param {function} callback - Callback to invoke to process the store data.
* @param {function} onFail - Callback to invoke if an operation fails.
*/
const getStoreIfUpdated = async (storeId, lastRootHash, callback, onFail) => {
try {
const rootResponse = await dataLayer.getRoot(storeId);

if (rootResponse.confirmed && rootResponse.hash !== lastRootHash) {
const curriedCallback = (data) => callback(rootResponse.hash, data);

await getStoreData(
storeId,
curriedCallback,
onFail,
rootResponse.hash,
0,
);
}
} catch (error) {
logger.error(error.message);
onFail(error.message);
}
};

Expand Down
Loading
Loading