Commit 37c9a188 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Media: Store the date of last access in a separate field

So that we can use it for vacuuming old external media
parent 2fe4350e
......@@ -62,12 +62,14 @@ Media::Media( MediaLibraryPtr ml, sqlite::Row& row )
, m_metadata( m_ml, IMetadata::EntityType::Media )
, m_changed( false )
{
time_t dummy;
row >> m_id
>> m_type
>> m_subType
>> m_duration
>> m_playCount
>> m_lastPlayedDate
>> dummy
>> m_insertionDate
>> m_releaseDate
>> m_thumbnailId
......@@ -178,9 +180,11 @@ int Media::playCount() const
bool Media::increasePlayCount()
{
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
"play_count = ?, last_played_date = ? WHERE id_media = ?";
"play_count = ?, last_played_date = ?, real_last_played_date = ? "
"WHERE id_media = ?";
auto lastPlayedDate = time( nullptr );
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, m_playCount + 1, lastPlayedDate, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, m_playCount + 1,
lastPlayedDate, lastPlayedDate, m_id ) == false )
return false;
m_playCount++;
m_lastPlayedDate = lastPlayedDate;
......
......@@ -27,13 +27,14 @@
#include "database/tables/Media_v14.sql"
"INSERT INTO " + MediaTable::Name + "("
"id_media, type, subtype, duration, play_count, last_played_date, insertion_date,"
"id_media, type, subtype, duration, play_count, last_played_date, real_last_played_date, insertion_date,"
"release_date, thumbnail_id, thumbnail_generated, title, filename, is_favorite,"
"is_present) "
"SELECT id_media, type, ifnull(subtype, " +
std::to_string( static_cast<typename std::underlying_type<IMedia::SubType>::type>(
IMedia::SubType::Unknown ) )
+ "), duration, play_count, last_played_date,"
"strftime('%s', 'now'),"
"insertion_date, release_date, "
"CASE thumbnail WHEN NULL THEN 0 WHEN '' THEN 0 ELSE id_media END,"
"CASE thumbnail WHEN NULL THEN 0 WHEN '' THEN 0 ELSE 1 END,"
......
......@@ -7,6 +7,7 @@
"duration INTEGER DEFAULT -1,"
"play_count UNSIGNED INTEGER,"
"last_played_date UNSIGNED INTEGER,"
"real_last_played_date UNSIGNED INTEGER,"
"insertion_date UNSIGNED INTEGER,"
"release_date UNSIGNED INTEGER,"
"thumbnail_id INTEGER,"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment