Skip to content

Commit

Permalink
feat: publish only non-empty messages to pub-sub
Browse files Browse the repository at this point in the history
  • Loading branch information
KanievskyiDanylo committed Dec 24, 2024
1 parent 948a9c0 commit a0bac11
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/lib/pub-sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ export class ExpKeyValuePubSub {
}

publish(data: Record<string, unknown>, ttl: number) {
const expiresAt = Math.round(Date.now() / 1000) + ttl;
this.logger.info(
`Publishing keys: '${Object.keys(data)}', expiresAt: '${expiresAt}'`,
);
if (Object.keys(data).length > 0) {
const expiresAt = Math.round(Date.now() / 1000) + ttl;
this.logger.info(
`Publishing keys: '${Object.keys(data)}', expiresAt: '${expiresAt}'`,
);

this.dexHelper.cache.publish(
this.channel,
JSON.stringify({ expiresAt, data }),
);
this.dexHelper.cache.publish(
this.channel,
JSON.stringify({ expiresAt, data }),
);
}
}

handleSubscription(msg: KeyValuePubSubMsg) {
Expand Down Expand Up @@ -168,8 +170,10 @@ export class NonExpSetPubSub {
}

publish(msg: SetPubSubMsg) {
this.logger.info(`Publishing msg: '${msg}'`);
this.dexHelper.cache.publish(this.channel, JSON.stringify(msg));
if (msg.length > 0) {
this.logger.info(`Publishing msg: '${msg}'`);
this.dexHelper.cache.publish(this.channel, JSON.stringify(msg));
}
}

handleSubscription(set: SetPubSubMsg) {
Expand Down

0 comments on commit a0bac11

Please sign in to comment.