@meshmakers/octo-services 3.5.380 → 3.5.390

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8719,6 +8719,7 @@ function deliveryStateOf(subjectId, states) {
8719
8719
  function toEntityId(ref) {
8720
8720
  return { rtId: ref.rtId, ckTypeId: ref.ckTypeId };
8721
8721
  }
8722
+ const USERS_CACHE_MS = 60_000;
8722
8723
  class NotificationSubscriptionService {
8723
8724
  getSubscriptionsGQL = inject(NotificationsGetSubscriptionsDtoGQL);
8724
8725
  getSubscriptionGQL = inject(NotificationsGetSubscriptionDtoGQL);
@@ -8732,6 +8733,8 @@ class NotificationSubscriptionService {
8732
8733
  communication = inject(CommunicationService);
8733
8734
  cronParser = inject(CronParserService);
8734
8735
  candidates = inject(NOTIFICATION_RECIPIENT_CANDIDATES);
8736
+ tenantIdProvider = inject(TENANT_ID_PROVIDER, { optional: true });
8737
+ usersCache = new Map();
8735
8738
  async getSubscriptions(request) {
8736
8739
  const result = await firstValueFrom(this.getSubscriptionsGQL.fetch({
8737
8740
  variables: {
@@ -8769,8 +8772,22 @@ class NotificationSubscriptionService {
8769
8772
  undeploy(tenantId, subscriptionRtId) {
8770
8773
  return this.communication.undeployNotificationSubscription(tenantId, subscriptionRtId);
8771
8774
  }
8772
- loadUsers() {
8773
- return this.candidates.load();
8775
+ async loadUsers() {
8776
+ const tenantId = await this.tenantIdProvider?.();
8777
+ if (!tenantId)
8778
+ return this.candidates.load();
8779
+ const cached = this.usersCache.get(tenantId);
8780
+ if (cached && (cached.loadedAt === null || Date.now() - cached.loadedAt < USERS_CACHE_MS))
8781
+ return cached.users;
8782
+ const entry = { loadedAt: null, users: this.candidates.load() };
8783
+ this.usersCache.set(tenantId, entry);
8784
+ entry.users.then(() => {
8785
+ entry.loadedAt = Date.now();
8786
+ }, () => {
8787
+ if (this.usersCache.get(tenantId) === entry)
8788
+ this.usersCache.delete(tenantId);
8789
+ });
8790
+ return entry.users;
8774
8791
  }
8775
8792
  scheduleIssue(cronExpression) {
8776
8793
  return notificationScheduleIssue((cron, count) => this.cronParser.getNextExecutions(cron, count), cronExpression);
@@ -8928,7 +8945,7 @@ class NotificationSubscriptionService {
8928
8945
  }
8929
8946
  async usersById() {
8930
8947
  try {
8931
- return new Map((await this.candidates.load()).map(user => [user.id, user]));
8948
+ return new Map((await this.loadUsers()).map(user => [user.id, user]));
8932
8949
  }
8933
8950
  catch {
8934
8951
  return null;
@@ -8943,6 +8960,7 @@ class NotificationSubscriptionService {
8943
8960
  ckTypeId: item.ckTypeId,
8944
8961
  subjectId: item.subjectId,
8945
8962
  userLabel: user?.label ?? item.subjectId,
8963
+ user: user ?? null,
8946
8964
  cronExpression: item.cronExpression,
8947
8965
  timeZone: item.timeZone ?? null,
8948
8966
  lastSentAt: state?.lastSentAt ?? null,