Improve SQL queries
This commit is contained in:
parent
4a0b71d3d7
commit
586c2375fd
@ -219,11 +219,11 @@ function cancelOrder(type, id, floID) {
|
|||||||
|
|
||||||
function getAccountDetails(floID) {
|
function getAccountDetails(floID) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let select = [];
|
let promises = [
|
||||||
select.push(["token, quantity", "UserBalance"]);
|
DB.query("SELECT token, quantity FROM UserBalance WHERE floID=?", [floID]),
|
||||||
select.push(["id, asset, quantity, minPrice, time_placed", "SellOrder"]);
|
DB.query("SELECT id, asset, quantity, minPrice, time_placed FROM SellOrder WHERE floID=?", [floID]),
|
||||||
select.push(["id, asset, quantity, maxPrice, time_placed", "BuyOrder"]);
|
DB.query("SELECT id, asset, quantity, maxPrice, time_placed FROM BuyOrder WHERE floID=?", [floID])
|
||||||
let promises = select.map(a => DB.query(`SELECT ${a[0]} FROM ${a[1]} WHERE floID=? ${a[2] || ""}`, [floID]));
|
];
|
||||||
Promise.allSettled(promises).then(results => {
|
Promise.allSettled(promises).then(results => {
|
||||||
let response = {
|
let response = {
|
||||||
floID: floID,
|
floID: floID,
|
||||||
|
|||||||
@ -48,7 +48,7 @@ function getPastRate(asset, hrs = 24) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHistory(asset, duration) {
|
function getHistory(asset, duration = '') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
duration = getHistory.validateDuration(duration);
|
duration = getHistory.validateDuration(duration);
|
||||||
let statement = "SELECT " +
|
let statement = "SELECT " +
|
||||||
@ -56,7 +56,7 @@ function getHistory(asset, duration) {
|
|||||||
" FROM PriceHistory WHERE asset=?" + (duration ? " AND rec_time >= NOW() - INTERVAL " + duration : "") +
|
" FROM PriceHistory WHERE asset=?" + (duration ? " AND rec_time >= NOW() - INTERVAL " + duration : "") +
|
||||||
(!duration || duration.endsWith("month") || duration.endsWith("year") ? " GROUP BY time" : "") +
|
(!duration || duration.endsWith("month") || duration.endsWith("year") ? " GROUP BY time" : "") +
|
||||||
" ORDER BY time";
|
" ORDER BY time";
|
||||||
DB.query(statement, asset)
|
DB.query(statement, [asset])
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
});
|
});
|
||||||
|
|||||||
@ -221,7 +221,9 @@ function refreshBlockchainData(nodeList = []) {
|
|||||||
let values = [fund_id, fund.start_date, fund.BTC_base, fund.USD_base, fund.fee, fund.duration];
|
let values = [fund_id, fund.start_date, fund.BTC_base, fund.USD_base, fund.fee, fund.duration];
|
||||||
if (fund.tapoutInterval)
|
if (fund.tapoutInterval)
|
||||||
values.push(fund.topoutWindow, fund.tapoutInterval.join(','));
|
values.push(fund.topoutWindow, fund.tapoutInterval.join(','));
|
||||||
txQueries.push([`INSERT INTO BobsFund(fund_id, begin_date, btc_base, usd_base, fee, duration ${fund.tapoutInterval ? ", tapout_window, tapout_interval" : ""}) VALUE (?) ON DUPLICATE KEY UPDATE fund_id=fund_id`, [values]])
|
else
|
||||||
|
values.push(null, null);
|
||||||
|
txQueries.push(["INSERT INTO BobsFund(fund_id, begin_date, btc_base, usd_base, fee, duration, tapout_window, tapout_interval) VALUE (?) ON DUPLICATE KEY UPDATE fund_id=fund_id", [values]])
|
||||||
} else
|
} else
|
||||||
fund_id = fund_id.pop().match(/[a-z0-9]{64}/).pop();
|
fund_id = fund_id.pop().match(/[a-z0-9]{64}/).pop();
|
||||||
let investments = Object.entries(fund.investments).map(a => [fund_id, a[0], a[1].amount]);
|
let investments = Object.entries(fund.investments).map(a => [fund_id, a[0], a[1].amount]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user