feature/IO-2742-redis - Checkpoint, All optimizations to prevent multiple requests to redis have been applied. Things like using lists for the Log Events, to getting and setting multiple values at the same time when given the chance.
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -12,7 +12,7 @@ const AxiosLib = require("axios").default;
|
||||
const axios = AxiosLib.create();
|
||||
const { PBS_ENDPOINTS, PBS_CREDENTIALS } = require("./pbs-constants");
|
||||
const { CheckForErrors } = require("./pbs-job-export");
|
||||
const { getSessionData, setSessionData } = require("../../../server");
|
||||
const { getSessionData, getMultipleSessionData, setMultipleSessionData } = require("../../../server");
|
||||
const uuid = require("uuid").v4;
|
||||
|
||||
axios.interceptors.request.use(
|
||||
@@ -66,8 +66,10 @@ async function PbsCalculateAllocationsAp(socket, billids) {
|
||||
const { bills, bodyshops } = await QueryBillData(socket, billids);
|
||||
const bodyshop = bodyshops[0];
|
||||
|
||||
await setSessionData(socket.id, "bills", bills);
|
||||
await setSessionData(socket.id, "bodyshop", bodyshop);
|
||||
await setMultipleSessionData(socket.id, {
|
||||
bills,
|
||||
bodyshop
|
||||
});
|
||||
|
||||
const txEnvelope = await getSessionData(socket.id, "txEnvelope");
|
||||
|
||||
@@ -221,12 +223,12 @@ function getCostAccount(billline, respcenters) {
|
||||
exports.PbsExportAp = async function (socket, { billids, txEnvelope }) {
|
||||
await CdkBase.createLogEvent(socket, "DEBUG", `Exporting selected AP.`);
|
||||
|
||||
//apAllocations has the same shape as the lines key for the accounting posting to PBS.
|
||||
const apAllocations = await PbsCalculateAllocationsAp(socket, billids);
|
||||
await setSessionData(socket.id, "apAllocations", apAllocations);
|
||||
|
||||
// Store txEnvelope in session
|
||||
await setSessionData(socket.id, "txEnvelope", txEnvelope);
|
||||
await setMultipleSessionData(socket.id, {
|
||||
apAllocations,
|
||||
txEnvelope
|
||||
});
|
||||
|
||||
for (const allocation of apAllocations) {
|
||||
const { billid, ...restAllocation } = allocation;
|
||||
@@ -257,8 +259,7 @@ exports.PbsExportAp = async function (socket, { billids, txEnvelope }) {
|
||||
};
|
||||
|
||||
async function MarkApExported(socket, billids) {
|
||||
const bills = await getSessionData(socket.id, "bills");
|
||||
const bodyshop = await getSessionData(socket.id, "bodyshop");
|
||||
const { bills, bodyshop } = await getMultipleSessionData(socket.id, ["bills", "bodyshop"]);
|
||||
|
||||
await CdkBase.createLogEvent(socket, "DEBUG", `Marking bills as exported for id ${billids}`);
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
|
||||
|
||||
@@ -12,7 +12,7 @@ const CalculateAllocations = require("../../cdk/cdk-calculate-allocations").defa
|
||||
const CdkBase = require("../../web-sockets/web-socket");
|
||||
const moment = require("moment-timezone");
|
||||
const Dinero = require("dinero.js");
|
||||
const { setSessionData, getSessionData } = require("../../../server");
|
||||
const { setSessionData, getSessionData, getMultipleSessionData, setMultipleSessionData } = require("../../../server");
|
||||
const InstanceManager = require("../../utils/instanceMgr").default;
|
||||
const axios = AxiosLib.create();
|
||||
|
||||
@@ -60,9 +60,10 @@ axios.interceptors.response.use(
|
||||
|
||||
exports.default = async function (socket, { txEnvelope, jobid }) {
|
||||
try {
|
||||
await setSessionData(socket.id, "logEvents", []);
|
||||
await setSessionData(socket.id, "recordid", jobid);
|
||||
await setSessionData(socket.id, "txEnvelope", txEnvelope);
|
||||
await setMultipleSessionData(socket.id, {
|
||||
recordid: jobid,
|
||||
txEnvelope
|
||||
});
|
||||
|
||||
await CdkBase.createLogEvent(socket, "DEBUG", `Received Job export request for id ${jobid}`);
|
||||
|
||||
@@ -536,8 +537,7 @@ async function UpsertVehicleData(socket, ownerRef) {
|
||||
|
||||
async function InsertAccountPostingData(socket) {
|
||||
try {
|
||||
const JobData = await getSessionData(socket.id, "JobData");
|
||||
const txEnvelope = await getSessionData(socket.id, "txEnvelope");
|
||||
const { JobData, txEnvelope } = await getMultipleSessionData(socket.id, ["JobData", "txEnvelope"]);
|
||||
|
||||
const allocations = await CalculateAllocations(socket, JobData.id);
|
||||
|
||||
@@ -650,8 +650,9 @@ async function InsertAccountPostingData(socket) {
|
||||
async function MarkJobExported(socket, jobid) {
|
||||
await CdkBase.createLogEvent(socket, "DEBUG", `Marking job as exported for id ${jobid}`);
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
|
||||
const JobData = await getSessionData(socket.id, "JobData");
|
||||
const transWips = await getSessionData(socket.id, "transWips");
|
||||
|
||||
const { JobData, transWips } = await getMultipleSessionData(socket.id, ["JobData", "transWips"]);
|
||||
|
||||
return await client
|
||||
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
|
||||
.request(queries.MARK_JOB_EXPORTED, {
|
||||
|
||||
Reference in New Issue
Block a user