mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Cost savings
The "cost" value was flawed for a couple of reasons. 1. Lots of messages are free, so in those instances the "cost" doesn't tell you anything 2. The query to get the rate was expensive and we don't have an obvious way to get it back very efficiently for large numbers of notifications. So we scrapped it.
This commit is contained in:
@@ -6,7 +6,7 @@ from sqlalchemy.dialects.postgresql import (
|
||||
UUID,
|
||||
JSON
|
||||
)
|
||||
from sqlalchemy import UniqueConstraint, and_, desc
|
||||
from sqlalchemy import UniqueConstraint, and_
|
||||
from sqlalchemy.orm import foreign, remote
|
||||
from notifications_utils.recipients import (
|
||||
validate_email_address,
|
||||
@@ -544,21 +544,6 @@ class Notification(db.Model):
|
||||
if personalisation:
|
||||
self._personalisation = encryption.encrypt(personalisation)
|
||||
|
||||
def cost(self):
|
||||
if not self.sent_by or self.billable_units == 0:
|
||||
return 0
|
||||
|
||||
provider_rate = db.session.query(
|
||||
ProviderRates
|
||||
).join(ProviderDetails).filter(
|
||||
ProviderDetails.identifier == self.sent_by,
|
||||
ProviderRates.provider_id == ProviderDetails.id
|
||||
).order_by(
|
||||
desc(ProviderRates.valid_from)
|
||||
).limit(1).one()
|
||||
|
||||
return float(provider_rate.rate * self.billable_units)
|
||||
|
||||
def completed_at(self):
|
||||
if self.status in [
|
||||
NOTIFICATION_DELIVERED,
|
||||
@@ -591,7 +576,6 @@ class Notification(db.Model):
|
||||
"line_5": None,
|
||||
"line_6": None,
|
||||
"postcode": None,
|
||||
"cost": self.cost(),
|
||||
"type": self.notification_type,
|
||||
"status": self.status,
|
||||
"template": template_dict,
|
||||
|
||||
Reference in New Issue
Block a user