SaveTransaction optimizations
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -867,8 +867,9 @@ export default class CpoOCPIClient extends OCPIClient {
} else if (OCPIUtilsService.isSuccessResponse(response.data)) {
const cdr = response.data.data as OCPICdr;
if (cdr) {
+ // CDR checked
transaction.ocpiData.cdrCheckedOn = new Date();
- await TransactionStorage.saveTransaction(this.tenant.id, transaction);
+ await TransactionStorage.saveTransactionOcpiData(this.tenant.id, transaction.id, transaction.ocpiData);
await Logging.logInfo({
tenantID: this.tenant.id,
source: transaction.chargeBoxID,

MODIFY
src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts
src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts
@@ -85,7 +85,7 @@ export default class OCPIPushCdrsTask extends SchedulerTask {
// Roaming
await OCPPUtils.processTransactionRoaming(tenant, transaction, chargingStation, TransactionAction.END);
// Save
- await TransactionStorage.saveTransaction(tenant.id, transaction);
+ await TransactionStorage.saveTransactionOcpiData(tenant.id, transaction.id, transaction.ocpiData);
// Ok
await Logging.logInfo({
tenantID: tenant.id,

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -237,7 +237,7 @@ export default class TransactionService {
// Roaming
await OCPPUtils.processTransactionRoaming(req.tenant, transaction, chargingStation, TransactionAction.END);
// Save
- await TransactionStorage.saveTransaction(req.user.tenantID, transaction);
+ await TransactionStorage.saveTransactionOcpiData(req.user.tenantID, transaction.id, transaction.ocpiData);
// Ok
await Logging.logInfo({
tenantID: req.user.tenantID,
@@ -273,7 +273,7 @@ export default class TransactionService {
// Post CDR
await OCPPUtils.processOICPTransaction(req.tenant, transaction, chargingStation, TransactionAction.END);
// Save
- await TransactionStorage.saveTransaction(req.user.tenantID, transaction);
+ await TransactionStorage.saveTransactionOicpData(req.user.tenantID, transaction.id, transaction.oicpData);
// Ok
await Logging.logInfo({
tenantID: req.user.tenantID,

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -717,23 +717,12 @@ export default class ChargingStationStorage {
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveChargingStationOcpiData');
// Check Tenant
await DatabaseUtils.checkTenant(tenantID);
- const ocpiDataMDB = {
- evses: ocpiData.evses.map((evse) => ({
- uid: evse.uid,
- evse_id: evse.evse_id,
- location_id: evse.location_id,
- status: evse.status,
- capabilities: evse.capabilities,
- connectors: evse.connectors,
- coordinates: evse.coordinates,
- last_updated: Utils.convertToDate(evse.last_updated),
- }))
- };
// Modify document
await global.database.getCollection<ChargingStation>(tenantID, 'chargingstations').findOneAndUpdate(
{ '_id': id },
- { $set: {
- ocpiData : ocpiDataMDB
+ {
+ $set: {
+ ocpiData
}
},
{ upsert: false });

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
-import RefundReport, { RefundStatus } from '../../types/Refund';
+import { BillingStatus, TransactionBillingData } from '../../types/Billing';
+import RefundReport, { RefundStatus, TransactionRefundData } from '../../types/Refund';
+import Transaction, { TransactionOcpiData, TransactionOicpData } from '../../types/Transaction';
import { TransactionInError, TransactionInErrorType } from '../../types/InError';
import global, { FilterParams } from './../../types/GlobalType';
-import { BillingStatus } from '../../types/Billing';
import Constants from '../../utils/Constants';
import ConsumptionStorage from './ConsumptionStorage';
import { DataResult } from '../../types/DataResult';
@@ -11,7 +12,6 @@ import DbParams from '../../types/database/DbParams';
import Logging from '../../utils/Logging';
import { NotifySessionNotStarted } from '../../types/UserNotifications';
import { ServerAction } from '../../types/Server';
-import Transaction from '../../types/Transaction';
import Utils from '../../utils/Utils';
import moment from 'moment';
@@ -211,6 +211,82 @@ export default class TransactionStorage {
return transactionToSave.id;
}
+ public static async saveTransactionOcpiData(tenantID: string, id: number,
+ ocpiData: TransactionOcpiData): Promise<void> {
+ // Debug
+ const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveTransactionOcpiData');
+ // Check Tenant
+ await DatabaseUtils.checkTenant(tenantID);
+ // Modify document
+ await global.database.getCollection<Transaction>(tenantID, 'transactions').findOneAndUpdate(
+ { '_id': id },
+ {
+ $set: {
+ ocpiData
+ }
+ },
+ { upsert: false });
+ // Debug
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveTransactionOcpiData', uniqueTimerID, ocpiData);
+ }
+
+ public static async saveTransactionOicpData(tenantID: string, id: number,
+ oicpData: TransactionOicpData): Promise<void> {
+ // Debug
+ const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveTransactionOicpData');
+ // Check Tenant
+ await DatabaseUtils.checkTenant(tenantID);
+ // Modify document
+ await global.database.getCollection<Transaction>(tenantID, 'transactions').findOneAndUpdate(
+ { '_id': id },
+ {
+ $set: {
+ oicpData
+ }
+ },
+ { upsert: false });
+ // Debug
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveTransactionOicpData', uniqueTimerID, oicpData);
+ }
+
+ public static async saveTransactionBillingData(tenantID: string, id: number,
+ billingData: TransactionBillingData): Promise<void> {
+ // Debug
+ const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveTransactionBillingData');
+ // Check Tenant
+ await DatabaseUtils.checkTenant(tenantID);
+ // Modify document
+ await global.database.getCollection<Transaction>(tenantID, 'transactions').findOneAndUpdate(
+ { '_id': id },
+ {
+ $set: {
+ billingData
+ }
+ },
+ { upsert: false });
+ // Debug
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveTransactionBillingData', uniqueTimerID, billingData);
+ }
+
+ public static async saveTransactionRefundData(tenantID: string, id: number,
+ refundData: TransactionRefundData): Promise<void> {
+ // Debug
+ const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveTransactionRefundData');
+ // Check Tenant
+ await DatabaseUtils.checkTenant(tenantID);
+ // Modify document
+ await global.database.getCollection<Transaction>(tenantID, 'transactions').findOneAndUpdate(
+ { '_id': id },
+ {
+ $set: {
+ refundData
+ }
+ },
+ { upsert: false });
+ // Debug
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveTransactionRefundData', uniqueTimerID, refundData);
+ }
+
public static async assignTransactionsToUser(tenantID: string, userID: string, tagID: string): Promise<void> {
// Debug
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'assignTransactionsToUser');

MODIFY
src/types/Billing.ts
src/types/Billing.ts
import { ActionsResponse } from './GlobalType';
import User from './User';
-export interface BillingTransactionData {
+export interface TransactionBillingData {
withBillingActive?: boolean;
lastUpdate?: Date;
stop?: BillingDataTransactionStop;

MODIFY
src/types/Refund.ts
src/types/Refund.ts
@@ -31,7 +31,7 @@ export interface ConcurLocation {
URI: string;
}
-export interface RefundTransactionData {
+export interface TransactionRefundData {
refundId: string;
refundedAt: Date;
reportId?: string;

MODIFY
src/types/Transaction.ts
src/types/Transaction.ts
@@ -2,7 +2,6 @@ import { Car, CarCatalog } from './Car';
import { ChargePointStatus, OCPP15TransactionData, OCPPMeterValue } from './ocpp/OCPPServer';
import Consumption, { AbstractCurrentConsumption } from './Consumption';
-import { BillingTransactionData } from './Billing';
import ChargingStation from '../types/ChargingStation';
import Company from './Company';
import { OCPICdr } from './ocpi/OCPICdr';
@@ -10,10 +9,11 @@ import { OCPISession } from './ocpi/OCPISession';
import { OICPChargeDetailRecord } from './oicp/OICPChargeDetailRecord';
import { OICPSession } from './oicp/OICPSession';
import { PricingModel } from './Pricing';
-import { RefundTransactionData } from './Refund';
import Site from './Site';
import SiteArea from './SiteArea';
import Tag from './Tag';
+import { TransactionBillingData } from './Billing';
+import { TransactionRefundData } from './Refund';
import User from './User';
export type InactivityStatusLevel =
@@ -75,7 +75,6 @@ export default interface Transaction extends AbstractCurrentConsumption {
tagID: string;
userID: string;
};
- refundData?: RefundTransactionData;
chargeBox?: ChargingStation;
meterStart: number;
timestamp: Date;
@@ -98,11 +97,12 @@ export default interface Transaction extends AbstractCurrentConsumption {
numberOfMeterValues: number;
uniqueId?: string;
values?: Consumption[];
- billingData?: BillingTransactionData;
ocpi?: boolean;
ocpiWithCdr?: boolean;
ocpiData?: TransactionOcpiData;
oicpData?: TransactionOicpData;
+ billingData?: TransactionBillingData;
+ refundData?: TransactionRefundData;
migrationTag?: string;
}

MODIFY
src/utils/Constants.ts
src/utils/Constants.ts
@@ -245,7 +245,7 @@ export default class Constants {
public static readonly OCPI_SERVER = 'OCPI Server';
public static readonly OCPI_SEPARATOR = '*';
public static readonly OCPI_RECORDS_LIMIT = 25;
- public static readonly OCPI_MAX_PARALLEL_REQUESTS = 5;
+ public static readonly OCPI_MAX_PARALLEL_REQUESTS = 2;
public static readonly OICP_SERVER = 'OICP Server';

SaveTransaction optimizations