Skip to content

Commit

Permalink
Append last online field to member model #2
Browse files Browse the repository at this point in the history
* last_online field in member model
* loading of message optimisation
  • Loading branch information
namezys authored May 1, 2018
2 parents 260ab4d + efc6335 commit f61b398
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hornet/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def list_favorites(self, page_num, page_size):

def list_message(self, member):
logger.info("List messages with %s", member)
last_message = models.Message.objects.filter(member=member).order_by('-datetime').first()
if last_message and last_message.datetime > member.last_online:
logger.debug("Member was online before last message. Read from DB")
return models.Message.objects.order_by('-datetime').all()
url = self.BASE_URL + "messages/" + member.network_id + "/conversation.json"
logger.debug("Request url %s", url)
response = self.session.get(url, params={"profile_id": member.network_id,
Expand Down
2 changes: 2 additions & 0 deletions hornet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Member(models.Model):
username = models.CharField(max_length=FIELD_LENGTH, null=False, blank=False)
age = models.IntegerField(null=True, blank=True)
distance = models.FloatField(null=True, blank=True)
last_online = models.DateTimeField(null=True, blank=True)

def __str__(self):
return "member #{0.pk}:{0.network_id}: {0.name} (age {0.age}) at {0.distance}".format(self)
Expand All @@ -47,6 +48,7 @@ def update(self, network_data):
self.username = network_data['account']['username']
self.age = network_data['age']
self.distance = network_data.get('distance')
self.last_online = dateparse.parse_datetime(network_data['last_online'])

@classmethod
def get(cls, account, network_data):
Expand Down

0 comments on commit f61b398

Please sign in to comment.