Normalize IDs in update distribution and subscription methods for consistency
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
- Updated the `distributeUpdate` and `subscribeToObjectUpdate` functions to normalize IDs by converting them to lowercase, ensuring consistent handling of object identifiers. - Modified the `getObjectUpdateSubscriptionKey` method to utilize the normalized ID, improving subscription key generation. - Enhanced logging to reflect normalized IDs during object update events, aiding in debugging and traceability.
This commit is contained in:
parent
ce3b9befeb
commit
76c3aa82dd
@ -581,7 +581,11 @@ async function getAuditLogs(idOrIds) {
|
||||
}
|
||||
|
||||
async function distributeUpdate(value, id, type) {
|
||||
await natsServer.publish(`${type}s.${id}.object`, { ...value, _id: id });
|
||||
const normalizedId = id == null ? id : String(id).toLowerCase();
|
||||
await natsServer.publish(`${type}s.${normalizedId}.object`, {
|
||||
...value,
|
||||
_id: normalizedId,
|
||||
});
|
||||
}
|
||||
|
||||
async function distributeStats(value, type) {
|
||||
|
||||
@ -206,7 +206,8 @@ export class UpdateManager {
|
||||
}
|
||||
|
||||
getObjectUpdateSubscriptionKey(objectType, id) {
|
||||
return `${objectType}:${id}`;
|
||||
const normalizedId = id == null ? id : String(id).toLowerCase();
|
||||
return `${objectType}:${normalizedId}`;
|
||||
}
|
||||
|
||||
matchesObjectTypeFilter(objectType, filter, value) {
|
||||
@ -298,8 +299,9 @@ export class UpdateManager {
|
||||
}
|
||||
|
||||
async subscribeToObjectUpdate(id, objectType) {
|
||||
logger.debug('Subscribing to object update...', id, objectType);
|
||||
const subject = `${objectType}s.${id}.object`;
|
||||
const normalizedId = id == null ? id : String(id).toLowerCase();
|
||||
logger.debug('Subscribing to object update...', normalizedId, objectType);
|
||||
const subject = `${objectType}s.${normalizedId}.object`;
|
||||
const owner = this.socketClient.socketId;
|
||||
|
||||
await natsServer.subscribe(subject, owner, (key, value) => {
|
||||
@ -307,7 +309,7 @@ export class UpdateManager {
|
||||
});
|
||||
|
||||
this.objectUpdateSubscriptions.add(
|
||||
this.getObjectUpdateSubscriptionKey(objectType, id)
|
||||
this.getObjectUpdateSubscriptionKey(objectType, normalizedId)
|
||||
);
|
||||
this.subscriptions.add(getSubscriptionKey(subject, owner));
|
||||
return { success: true };
|
||||
@ -321,9 +323,10 @@ export class UpdateManager {
|
||||
}
|
||||
|
||||
const { _id, ...object } = { ...expandedValue };
|
||||
logger.trace('Object update event:', _id, objectType);
|
||||
const normalizedId = _id == null ? _id : String(_id).toLowerCase();
|
||||
logger.trace('Object update event:', normalizedId, objectType);
|
||||
this.socketClient.socket.emit('objectUpdate', {
|
||||
_id,
|
||||
_id: normalizedId,
|
||||
objectType,
|
||||
object
|
||||
});
|
||||
@ -375,7 +378,8 @@ export class UpdateManager {
|
||||
}
|
||||
|
||||
async removeObjectUpdateListener(id, objectType) {
|
||||
const subject = `${objectType}s.${id}.object`;
|
||||
const normalizedId = id == null ? id : String(id).toLowerCase();
|
||||
const subject = `${objectType}s.${normalizedId}.object`;
|
||||
const owner = this.socketClient.socketId;
|
||||
|
||||
await natsServer.removeSubscription(subject, owner);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user