Przeglądaj źródła

fix delegate caching for payments

tags/v0.1.8
Jonathan Cobb 4 lat temu
rodzic
commit
109f45b02a
5 zmienionych plików z 18 dodań i 10 usunięć
  1. +7
    -6
      bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java
  2. +6
    -0
      bubble-server/src/main/java/bubble/model/cloud/notify/NotificationType.java
  3. +1
    -1
      bubble-server/src/main/java/bubble/notify/payment/PaymentMethodClaimNotification.java
  4. +3
    -2
      bubble-server/src/main/java/bubble/notify/payment/PaymentMethodValidationNotification.java
  5. +1
    -1
      bubble-server/src/main/java/bubble/service/notify/NotificationService.java

+ 7
- 6
bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java Wyświetl plik

@@ -8,6 +8,7 @@ import bubble.model.account.HasAccountNoName;
import bubble.model.cloud.CloudService;
import bubble.notify.payment.PaymentValidationResult;
import bubble.server.BubbleConfiguration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@@ -20,13 +21,9 @@ import org.cobbzilla.wizard.model.entityconfig.annotations.*;
import org.cobbzilla.wizard.validation.ValidationResult;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.*;

import static org.cobbzilla.util.daemon.ZillaRuntime.bool;
import static org.cobbzilla.util.daemon.ZillaRuntime.empty;
import static org.cobbzilla.util.daemon.ZillaRuntime.*;
import static org.cobbzilla.util.reflect.ReflectionUtil.copy;
import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENCRYPTED_STRING;
import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENC_PAD;
@@ -135,4 +132,8 @@ public class AccountPaymentMethod extends IdentifiableBase implements HasAccount

return result;
}

@JsonIgnore @Transient public String getCacheKey () {
return hashOf(getUuid(), account, cloud, paymentMethodType, paymentInfo);
}
}

+ 6
- 0
bubble-server/src/main/java/bubble/model/cloud/notify/NotificationType.java Wyświetl plik

@@ -131,4 +131,10 @@ public enum NotificationType {
: die("toResponse: no responseClass defined for "+this.name());
}

public boolean canReturnCachedResponse() {
// payment validation requests are never cached, because the response depends on data outside the message
// specifically, if the user does not have any validated email address, an error is returned
// but an identical notification can later return a different response, after the email has been validated
return this != payment_driver_validate;
}
}

+ 1
- 1
bubble-server/src/main/java/bubble/notify/payment/PaymentMethodClaimNotification.java Wyświetl plik

@@ -35,5 +35,5 @@ public class PaymentMethodClaimNotification extends SynchronousNotification {
}

@JsonIgnore @Transient @Getter(lazy=true) private final String cacheKey
= hashOf(hasPaymentMethod() ? paymentMethod.getUuid() : null, hasAccountPlan() ? accountPlan.getUuid() : null, cloud);
= hashOf(hasPaymentMethod() ? paymentMethod.getCacheKey() : null, hasAccountPlan() ? accountPlan.getUuid() : null, cloud);
}

+ 3
- 2
bubble-server/src/main/java/bubble/notify/payment/PaymentMethodValidationNotification.java Wyświetl plik

@@ -8,18 +8,19 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.Transient;

import static org.cobbzilla.util.daemon.ZillaRuntime.hashOf;

@NoArgsConstructor @AllArgsConstructor @Accessors(chain=true)
@NoArgsConstructor @AllArgsConstructor @Accessors(chain=true) @Slf4j
public class PaymentMethodValidationNotification extends SynchronousNotification {

@Getter @Setter private String cloud;
@Getter @Setter private AccountPaymentMethod paymentMethod;

@JsonIgnore @Transient @Getter(lazy=true) private final String cacheKey
= hashOf(cloud, paymentMethod != null ? paymentMethod.getUuid() : null);
= hashOf(cloud, paymentMethod != null ? paymentMethod.getCacheKey() : null);

}

+ 1
- 1
bubble-server/src/main/java/bubble/service/notify/NotificationService.java Wyświetl plik

@@ -129,7 +129,7 @@ public class NotificationService {
SynchronousNotification activeNotification;
synchronized (syncRequestCache) {
activeNotification = syncRequestCache.get(cacheKey);
if (activeNotification == null) {
if (activeNotification == null || !type.canReturnCachedResponse()) {
// no one else is calling, we are the activeNotification
syncRequestCache.put(cacheKey, notification);
activeNotification = notification;


Ładowanie…
Anuluj
Zapisz