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:
Paul Craig
2016-11-24 10:33:38 +00:00
parent f1ea39d4c0
commit 1fce30aaa7
4 changed files with 2 additions and 58 deletions

View File

@@ -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,