fixed low performance transactions

This commit is contained in:
Fran Jurmanović
2021-06-30 22:36:03 +02:00
parent 81505baf7a
commit 1b4d5e8725
4 changed files with 46 additions and 35 deletions

View File

@@ -50,31 +50,34 @@ func (cm *Subscription) ToTrans() *Transaction {
}
func (cm *Subscription) HasNew() bool {
trans := cm.TransactionType;
switch trans.Type {
case "monthly":
lastDate := time.Now().AddDate(0, -cm.CustomRange, 0)
if cm.LastTransactionDate.Before(lastDate) {
return true
trans := cm.TransactionType
if trans != nil {
switch trans.Type {
case "monthly":
lastDate := time.Now().AddDate(0, -cm.CustomRange, 0)
if cm.LastTransactionDate.Before(lastDate) {
return true
}
return false
case "weekly":
lastDate := time.Now().AddDate(0, 0, -(7*cm.CustomRange))
if cm.LastTransactionDate.Before(lastDate) {
return true
}
return false
case "daily":
lastDate := time.Now().AddDate(0, 0, -cm.CustomRange)
if cm.LastTransactionDate.Before(lastDate) {
return true
}
return false
default:
lastDate := time.Now().AddDate(-cm.CustomRange, 0, 0)
if cm.LastTransactionDate.Before(lastDate) {
return true
}
return false
}
return false
case "weekly":
lastDate := time.Now().AddDate(0, 0, -(7*cm.CustomRange))
if cm.LastTransactionDate.Before(lastDate) {
return true
}
return false
case "daily":
lastDate := time.Now().AddDate(0, 0, -cm.CustomRange)
if cm.LastTransactionDate.Before(lastDate) {
return true
}
return false
default:
lastDate := time.Now().AddDate(-cm.CustomRange, 0, 0)
if cm.LastTransactionDate.Before(lastDate) {
return true
}
return false
}
return true
}