add access timestamp and count updates with session commits

not sure how well I'm doing the session commits, I need help lol
This commit is contained in:
Xevion
2019-12-24 03:17:11 -06:00
parent 5136af6e65
commit 250b39b462
2 changed files with 13 additions and 2 deletions

View File

@@ -12,9 +12,16 @@ class YouTubeAudio(db.Model):
uploader = db.Column(db.String(32)) # 20 -> 32
filename = db.Column(db.String(156)) # 128 + 11 + 1 -> 156
duration = db.Column(db.Integer)
access_count = db.Column(db.Integer)
download_timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
last_access_timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
def access(self):
self.access_count += 1
self.last_access_timestamp = datetime.utcnow()
db.session.commit()
return self
def getPath(self):
return os.path.join('app', 'sounds', 'youtube', self.filename)