Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
VideoLAN
medialibrary
Commits
add3f468
Commit
add3f468
authored
Jul 16, 2018
by
Hugo Beauzée-Luyssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MediaLibrary: Vacuum old external & stream media
parent
37c9a188
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
0 deletions
+44
-0
src/Media.cpp
src/Media.cpp
+11
-0
src/Media.h
src/Media.h
+1
-0
src/MediaLibrary.cpp
src/MediaLibrary.cpp
+1
-0
test/common/MediaLibraryTester.cpp
test/common/MediaLibraryTester.cpp
+7
-0
test/common/MediaLibraryTester.h
test/common/MediaLibraryTester.h
+1
-0
test/unittest/MediaTests.cpp
test/unittest/MediaTests.cpp
+23
-0
No files found.
src/Media.cpp
View file @
add3f468
...
...
@@ -778,4 +778,15 @@ void Media::clearHistory( MediaLibraryPtr ml )
t
->
commit
();
}
void
Media
::
removeOldMedia
(
MediaLibraryPtr
ml
,
std
::
chrono
::
seconds
maxLifeTime
)
{
const
std
::
string
req
=
"DELETE FROM "
+
policy
::
MediaTable
::
Name
+
" "
"WHERE real_last_played_date < ? AND ( type = ? OR type = ? ) "
"AND id_media NOT IN (SELECT media_id FROM PlaylistMediaRelation)"
;
auto
deadline
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
(
std
::
chrono
::
system_clock
::
now
()
-
maxLifeTime
).
time_since_epoch
()
);
sqlite
::
Tools
::
executeDelete
(
ml
->
getConn
(),
req
,
deadline
.
count
(),
IMedia
::
Type
::
External
,
IMedia
::
Type
::
Stream
);
}
}
src/Media.h
View file @
add3f468
...
...
@@ -147,6 +147,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
static
Query
<
IMedia
>
fetchStreamHistory
(
MediaLibraryPtr
ml
);
static
void
clearHistory
(
MediaLibraryPtr
ml
);
static
void
removeOldMedia
(
MediaLibraryPtr
ml
,
std
::
chrono
::
seconds
maxLifeTime
);
private:
static
std
::
string
sortRequest
(
const
QueryParameters
*
params
);
...
...
src/MediaLibrary.cpp
View file @
add3f468
...
...
@@ -370,6 +370,7 @@ bool MediaLibrary::start()
// Now that we know which devices are plugged, check for outdated devices
// Approximate 6 months for old device precision.
Device
::
removeOldDevices
(
this
,
std
::
chrono
::
seconds
{
3600
*
24
*
30
*
6
}
);
Media
::
removeOldMedia
(
this
,
std
::
chrono
::
seconds
{
3600
*
24
*
30
*
6
}
);
startDiscoverer
();
if
(
startParser
()
==
false
)
...
...
test/common/MediaLibraryTester.cpp
View file @
add3f468
...
...
@@ -220,3 +220,10 @@ void MediaLibraryTester::outdateAllDevices()
std
::
string
req
=
"UPDATE "
+
policy
::
DeviceTable
::
Name
+
" SET last_seen = 1"
;
sqlite
::
Tools
::
executeUpdate
(
getConn
(),
req
);
}
void
MediaLibraryTester
::
outdateAllExternalMedia
()
{
std
::
string
req
=
"UPDATE "
+
policy
::
MediaTable
::
Name
+
" SET real_last_played_date = 1 "
"WHERE type = ? OR type = ?"
;
sqlite
::
Tools
::
executeUpdate
(
getConn
(),
req
,
IMedia
::
Type
::
External
,
IMedia
::
Type
::
Stream
);
}
test/common/MediaLibraryTester.h
View file @
add3f468
...
...
@@ -78,6 +78,7 @@ public:
MediaPtr
addMedia
(
const
std
::
string
&
mrl
);
void
deleteMedia
(
int64_t
mediaId
);
void
outdateAllDevices
();
void
outdateAllExternalMedia
();
private:
std
::
shared_ptr
<
fs
::
IDirectory
>
dummyDirectory
;
...
...
test/unittest/MediaTests.cpp
View file @
add3f468
...
...
@@ -35,6 +35,7 @@
#include "mocks/FileSystem.h"
#include "mocks/DiscovererCbMock.h"
#include "compat/Thread.h"
#include "Playlist.h"
class
Medias
:
public
Tests
{
...
...
@@ -727,6 +728,28 @@ TEST_F( Medias, SearchExternal )
ASSERT_EQ
(
2u
,
media
.
size
()
);
}
TEST_F
(
Medias
,
VacuumOldExternal
)
{
auto
m1
=
ml
->
addExternalMedia
(
"foo.avi"
);
auto
m2
=
ml
->
addExternalMedia
(
"bar.mp3"
);
auto
s1
=
ml
->
addStream
(
"http://baz.mkv"
);
auto
playlist
=
ml
->
createPlaylist
(
"playlist"
);
playlist
->
append
(
*
m1
);
ml
->
outdateAllExternalMedia
();
Reload
();
m1
=
ml
->
media
(
m1
->
id
()
);
m2
=
ml
->
media
(
m2
->
id
()
);
s1
=
ml
->
media
(
s1
->
id
()
);
ASSERT_NE
(
nullptr
,
m1
);
ASSERT_EQ
(
nullptr
,
m2
);
ASSERT_EQ
(
nullptr
,
s1
);
}
class
FetchMedia
:
public
Tests
{
protected:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment