Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Maui
Vvave
Commits
7d066a15
Commit
7d066a15
authored
Jun 21, 2019
by
camilo higuita
Browse files
more performance issues
parent
ac74ec62
Changes
6
Hide whitespace changes
Inline
Side-by-side
db/collectionDB.cpp
View file @
7d066a15
...
...
@@ -26,6 +26,13 @@ using namespace BAE;
CollectionDB
::
CollectionDB
(
QObject
*
parent
)
:
QObject
(
parent
)
{
QObject
::
connect
(
qApp
,
&
QCoreApplication
::
aboutToQuit
,
[
this
]()
{
this
->
m_db
.
close
();
this
->
instance
->
deleteLater
();
this
->
instance
=
nullptr
;
});
this
->
name
=
QUuid
::
createUuid
().
toString
();
if
(
!
BAE
::
fileExists
(
BAE
::
CollectionDBPath
+
BAE
::
DBName
))
...
...
@@ -45,8 +52,6 @@ CollectionDB::CollectionDB(QObject *parent) : QObject(parent)
CollectionDB
::~
CollectionDB
()
{
qDebug
()
<<
"DELETING COLLECTIONDB SINGLETON"
;
this
->
m_db
.
close
();
delete
this
->
instance
;
}
CollectionDB
*
CollectionDB
::
instance
=
nullptr
;
...
...
@@ -65,6 +70,10 @@ CollectionDB *CollectionDB::getInstance()
}
}
void
CollectionDB
::
deleteInstance
()
{
delete
this
;
}
void
CollectionDB
::
prepareCollectionDB
()
{
...
...
db/collectionDB.h
View file @
7d066a15
...
...
@@ -16,116 +16,115 @@
#include
"../utils/bae.h"
enum
sourceTypes
{
{
LOCAL
,
ONLINE
,
DEVICE
};
};
class
CollectionDB
:
public
QObject
{
Q_OBJECT
public:
static
CollectionDB
*
getInstance
();
bool
insert
(
const
QString
&
tableName
,
const
QVariantMap
&
insertData
);
bool
update
(
const
QString
&
tableName
,
const
FMH
::
MODEL
&
updateData
,
const
QVariantMap
&
where
);
bool
update
(
const
QString
&
table
,
const
QString
&
column
,
const
QVariant
&
newValue
,
const
QVariant
&
op
,
const
QString
&
id
);
bool
remove
();
bool
execQuery
(
QSqlQuery
&
query
)
const
;
bool
execQuery
(
const
QString
&
queryTxt
);
/*basic public actions*/
void
prepareCollectionDB
();
bool
check_existance
(
const
QString
&
tableName
,
const
QString
&
searchId
,
const
QString
&
search
);
/* usefull actions */
void
insertArtwork
(
const
FMH
::
MODEL
&
track
);
bool
addTrack
(
const
FMH
::
MODEL
&
track
);
bool
updateTrack
(
const
FMH
::
MODEL
&
track
);
Q_INVOKABLE
bool
rateTrack
(
const
QString
&
path
,
const
int
&
value
);
Q_INVOKABLE
bool
colorTagTrack
(
const
QString
&
path
,
const
QString
&
value
);
Q_INVOKABLE
QString
trackColorTag
(
const
QString
&
path
);
bool
lyricsTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
Q_INVOKABLE
bool
playedTrack
(
const
QString
&
url
,
const
int
&
increment
=
1
);
bool
wikiTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
bool
tagsTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
,
const
QString
&
context
);
bool
albumTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
bool
trackTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
bool
wikiArtist
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
bool
tagsArtist
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
,
const
QString
&
context
=
""
);
bool
wikiAlbum
(
const
FMH
::
MODEL
&
track
,
QString
value
);
bool
tagsAlbum
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
,
const
QString
&
context
=
""
);
Q_INVOKABLE
bool
addPlaylist
(
const
QString
&
title
);
bool
trackPlaylist
(
const
QString
&
url
,
const
QString
&
playlist
);
bool
addFolder
(
const
QString
&
url
);
bool
removeFolder
(
const
QString
&
url
);
bool
favTrack
(
const
QString
&
path
,
const
bool
&
value
);
FMH
::
MODEL_LIST
getDBData
(
const
QStringList
&
urls
);
FMH
::
MODEL_LIST
getDBData
(
const
QString
&
queryTxt
);
QVariantList
getDBDataQML
(
const
QString
&
queryTxt
);
static
QStringList
dataToList
(
const
FMH
::
MODEL_LIST
&
list
,
const
FMH
::
MODEL_KEY
&
key
);
FMH
::
MODEL_LIST
getAlbumTracks
(
const
QString
&
album
,
const
QString
&
artist
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
TRACK
,
const
BAE
::
W
&
order
=
BAE
::
W
::
ASC
);
FMH
::
MODEL_LIST
getArtistTracks
(
const
QString
&
artist
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
ALBUM
,
const
BAE
::
W
&
order
=
BAE
::
W
::
ASC
);
FMH
::
MODEL_LIST
getBabedTracks
(
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
COUNT
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getSearchedTracks
(
const
FMH
::
MODEL_KEY
&
where
,
const
QString
&
search
);
FMH
::
MODEL_LIST
getPlaylistTracks
(
const
QString
&
playlist
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
ADDDATE
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getMostPlayedTracks
(
const
int
&
greaterThan
=
1
,
const
int
&
limit
=
50
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
COUNT
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getFavTracks
(
const
int
&
stars
=
1
,
const
int
&
limit
=
50
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
RATE
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getRecentTracks
(
const
int
&
limit
=
50
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
ADDDATE
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getOnlineTracks
(
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
ADDDATE
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
Q_INVOKABLE
QStringList
getSourcesFolders
();
QStringList
getTrackTags
(
const
QString
&
path
);
Q_INVOKABLE
int
getTrackStars
(
const
QString
&
path
);
// QStringList getArtistTags(const QString &artist);
// QStringList getAlbumTags(const QString &album, const QString &artist);
QStringList
getArtistAlbums
(
const
QString
&
artist
);
FMH
::
MODEL_LIST
getPlaylists
();
QStringList
getPlaylistsList
();
Q_INVOKABLE
bool
removePlaylistTrack
(
const
QString
&
url
,
const
QString
&
playlist
);
Q_INVOKABLE
bool
removePlaylist
(
const
QString
&
playlist
);
Q_INVOKABLE
void
removeMissingTracks
();
bool
removeArtist
(
const
QString
&
artist
);
bool
cleanArtists
();
bool
removeAlbum
(
const
QString
&
album
,
const
QString
&
artist
);
bool
cleanAlbums
();
Q_INVOKABLE
bool
removeSource
(
const
QString
&
url
);
Q_INVOKABLE
bool
removeTrack
(
const
QString
&
path
);
QSqlQuery
getQuery
(
const
QString
&
queryTxt
);
/*useful tools*/
sourceTypes
sourceType
(
const
QString
&
url
);
void
openDB
(
const
QString
&
name
);
Q_OBJECT
public:
static
CollectionDB
*
getInstance
();
void
deleteInstance
();
bool
insert
(
const
QString
&
tableName
,
const
QVariantMap
&
insertData
);
bool
update
(
const
QString
&
tableName
,
const
FMH
::
MODEL
&
updateData
,
const
QVariantMap
&
where
);
bool
update
(
const
QString
&
table
,
const
QString
&
column
,
const
QVariant
&
newValue
,
const
QVariant
&
op
,
const
QString
&
id
);
bool
remove
();
bool
execQuery
(
QSqlQuery
&
query
)
const
;
bool
execQuery
(
const
QString
&
queryTxt
);
/*basic public actions*/
void
prepareCollectionDB
();
bool
check_existance
(
const
QString
&
tableName
,
const
QString
&
searchId
,
const
QString
&
search
);
/* usefull actions */
void
insertArtwork
(
const
FMH
::
MODEL
&
track
);
bool
addTrack
(
const
FMH
::
MODEL
&
track
);
bool
updateTrack
(
const
FMH
::
MODEL
&
track
);
Q_INVOKABLE
bool
rateTrack
(
const
QString
&
path
,
const
int
&
value
);
Q_INVOKABLE
bool
colorTagTrack
(
const
QString
&
path
,
const
QString
&
value
);
Q_INVOKABLE
QString
trackColorTag
(
const
QString
&
path
);
bool
lyricsTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
Q_INVOKABLE
bool
playedTrack
(
const
QString
&
url
,
const
int
&
increment
=
1
);
bool
wikiTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
bool
tagsTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
,
const
QString
&
context
);
bool
albumTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
bool
trackTrack
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
bool
wikiArtist
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
);
bool
tagsArtist
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
,
const
QString
&
context
=
""
);
bool
wikiAlbum
(
const
FMH
::
MODEL
&
track
,
QString
value
);
bool
tagsAlbum
(
const
FMH
::
MODEL
&
track
,
const
QString
&
value
,
const
QString
&
context
=
""
);
Q_INVOKABLE
bool
addPlaylist
(
const
QString
&
title
);
bool
trackPlaylist
(
const
QString
&
url
,
const
QString
&
playlist
);
bool
addFolder
(
const
QString
&
url
);
bool
removeFolder
(
const
QString
&
url
);
bool
favTrack
(
const
QString
&
path
,
const
bool
&
value
);
FMH
::
MODEL_LIST
getDBData
(
const
QStringList
&
urls
);
FMH
::
MODEL_LIST
getDBData
(
const
QString
&
queryTxt
);
QVariantList
getDBDataQML
(
const
QString
&
queryTxt
);
static
QStringList
dataToList
(
const
FMH
::
MODEL_LIST
&
list
,
const
FMH
::
MODEL_KEY
&
key
);
FMH
::
MODEL_LIST
getAlbumTracks
(
const
QString
&
album
,
const
QString
&
artist
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
TRACK
,
const
BAE
::
W
&
order
=
BAE
::
W
::
ASC
);
FMH
::
MODEL_LIST
getArtistTracks
(
const
QString
&
artist
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
ALBUM
,
const
BAE
::
W
&
order
=
BAE
::
W
::
ASC
);
FMH
::
MODEL_LIST
getBabedTracks
(
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
COUNT
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getSearchedTracks
(
const
FMH
::
MODEL_KEY
&
where
,
const
QString
&
search
);
FMH
::
MODEL_LIST
getPlaylistTracks
(
const
QString
&
playlist
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
ADDDATE
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getMostPlayedTracks
(
const
int
&
greaterThan
=
1
,
const
int
&
limit
=
50
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
COUNT
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getFavTracks
(
const
int
&
stars
=
1
,
const
int
&
limit
=
50
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
RATE
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getRecentTracks
(
const
int
&
limit
=
50
,
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
ADDDATE
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
FMH
::
MODEL_LIST
getOnlineTracks
(
const
FMH
::
MODEL_KEY
&
orderBy
=
FMH
::
MODEL_KEY
::
ADDDATE
,
const
BAE
::
W
&
order
=
BAE
::
W
::
DESC
);
Q_INVOKABLE
QStringList
getSourcesFolders
();
QStringList
getTrackTags
(
const
QString
&
path
);
Q_INVOKABLE
int
getTrackStars
(
const
QString
&
path
);
// QStringList getArtistTags(const QString &artist);
// QStringList getAlbumTags(const QString &album, const QString &artist);
QStringList
getArtistAlbums
(
const
QString
&
artist
);
FMH
::
MODEL_LIST
getPlaylists
();
QStringList
getPlaylistsList
();
Q_INVOKABLE
bool
removePlaylistTrack
(
const
QString
&
url
,
const
QString
&
playlist
);
Q_INVOKABLE
bool
removePlaylist
(
const
QString
&
playlist
);
Q_INVOKABLE
void
removeMissingTracks
();
bool
removeArtist
(
const
QString
&
artist
);
bool
cleanArtists
();
bool
removeAlbum
(
const
QString
&
album
,
const
QString
&
artist
);
bool
cleanAlbums
();
Q_INVOKABLE
bool
removeSource
(
const
QString
&
url
);
Q_INVOKABLE
bool
removeTrack
(
const
QString
&
path
);
QSqlQuery
getQuery
(
const
QString
&
queryTxt
);
/*useful tools*/
sourceTypes
sourceType
(
const
QString
&
url
);
void
openDB
(
const
QString
&
name
);
private:
static
CollectionDB
*
instance
;
QString
name
;
QSqlDatabase
m_db
;
explicit
CollectionDB
(
QObject
*
parent
=
nullptr
);
~
CollectionDB
()
override
;
static
CollectionDB
*
instance
;
public
slots
:
QString
name
;
QSqlDatabase
m_db
;
explicit
CollectionDB
(
QObject
*
parent
=
nullptr
);
~
CollectionDB
();
signals:
void
trackInserted
();
void
artworkInserted
(
const
FMH
::
MODEL
&
albumMap
);
void
DBactionFinished
();
void
albumsCleaned
(
const
int
&
amount
);
void
artistsCleaned
(
const
int
&
amount
);
public
slots
:
signals:
void
trackInserted
();
void
artworkInserted
(
const
FMH
::
MODEL
&
albumMap
);
void
DBactionFinished
();
void
albumsCleaned
(
const
int
&
amount
);
void
artistsCleaned
(
const
int
&
amount
);
};
#endif // COLLECTION_H
models/albums/albumsmodel.cpp
View file @
7d066a15
...
...
@@ -7,10 +7,11 @@ AlbumsModel::AlbumsModel(QObject *parent) : BaseList(parent)
{
this
->
db
=
CollectionDB
::
getInstance
();
connect
(
this
,
&
AlbumsModel
::
queryChanged
,
this
,
&
AlbumsModel
::
setList
);
QObject
::
connect
(
qApp
,
&
QCoreApplication
::
aboutToQuit
,
[
=
]()
{
pool
.
waitForDone
();
});
}
AlbumsModel
::~
AlbumsModel
()
{
}
FMH
::
MODEL_LIST
AlbumsModel
::
items
()
const
...
...
@@ -132,8 +133,6 @@ void AlbumsModel::runBrain()
watcher
->
deleteLater
();
});
auto
func
=
[
=
]()
{
QList
<
PULPO
::
REQUEST
>
requests
;
...
...
@@ -192,16 +191,28 @@ void AlbumsModel::runBrain()
Pulpo
pulpo
;
QEventLoop
loop
;
QObject
::
connect
(
&
pulpo
,
&
Pulpo
::
finished
,
&
loop
,
&
QEventLoop
::
quit
);
bool
stop
=
false
;
// QObject::connect(qApp, &QCoreApplication::aboutToQuit, [&]()
// {
// stop = true;
// loop.quit();
// });
QObject
::
connect
(
this
,
&
AlbumsModel
::
destroyed
,
[
&
]()
{
stop
=
true
;
loop
.
quit
();
});
for
(
auto
i
=
0
;
i
<
requests
.
size
();
i
++
)
{
pulpo
.
request
(
requests
.
at
(
i
));
loop
.
exec
();
if
(
stop
)
return
;
}
};
QFuture
<
void
>
t1
=
QtConcurrent
::
run
(
&
pool
,
func
);
QFuture
<
void
>
t1
=
QtConcurrent
::
run
(
func
);
watcher
->
setFuture
(
t1
);
}
...
...
models/albums/albumsmodel.h
View file @
7d066a15
...
...
@@ -3,7 +3,6 @@
#include
<QObject>
#include
"models/baselist.h"
#include
<QThreadPool>
class
CollectionDB
;
class
AlbumsModel
:
public
BaseList
...
...
@@ -30,6 +29,7 @@ public:
Q_ENUM
(
QUERY
)
explicit
AlbumsModel
(
QObject
*
parent
=
nullptr
);
~
AlbumsModel
();
FMH
::
MODEL_LIST
items
()
const
override
;
...
...
@@ -50,7 +50,6 @@ private:
void
runBrain
();
void
updateArtwork
(
const
int
index
,
const
QString
&
artwork
);
QThreadPool
pool
;
signals:
void
queryChanged
();
...
...
vvave.cpp
View file @
7d066a15
...
...
@@ -56,50 +56,6 @@ vvave::vvave(QObject *parent) : QObject(parent)
vvave
::~
vvave
()
{}
void
vvave
::
runBrain
()
{
QFutureWatcher
<
void
>
*
watcher
=
new
QFutureWatcher
<
void
>
;
QObject
::
connect
(
watcher
,
&
QFutureWatcher
<
void
>::
finished
,
[
=
]()
{
watcher
->
deleteLater
();
emit
this
->
refreshAlbums
();
});
// QObject::connect(qApp, &QCoreApplication::aboutToQuit, [=]()
// {
// if(watcher != nullptr)
// watcher->future().waitForFinished();
// });
// auto func = [=]()
// {
// the album artworks package
// BRAIN::PACKAGE albumPackage;
// albumPackage.ontology = PULPO::ONTOLOGY::ALBUM;
// albumPackage.info = PULPO::INFO::ARTWORK;
// albumPackage.callback = [=]()
// {
// emit this->refreshAlbums();
// };
// BRAIN::PACKAGE artistPackage;
// artistPackage.ontology = PULPO::ONTOLOGY::ARTIST;
// artistPackage.info = PULPO::INFO::ARTWORK;
// artistPackage.callback = [=]()
// {
// emit this->refreshArtists();
// };
// BRAIN::synapse(BRAIN::PACKAGES() << albumPackage /*<< artistPackage*/);
// };
// QFuture<void> t1 = QtConcurrent::run(func);
// watcher->setFuture(t1);
}
void
vvave
::
checkCollection
(
const
QStringList
&
paths
,
std
::
function
<
void
(
uint
)
>
cb
)
{
QFutureWatcher
<
uint
>
*
watcher
=
new
QFutureWatcher
<
uint
>
;
...
...
@@ -150,7 +106,6 @@ void vvave::scanDir(const QStringList &paths)
this
->
checkCollection
(
paths
,
[
=
](
uint
size
)
{
emit
this
->
refreshTables
(
size
);
// this->runBrain();
});
}
...
...
vvave.h
View file @
7d066a15
...
...
@@ -14,7 +14,6 @@ private:
Notify
*
notify
;
CollectionDB
*
db
;
void
checkCollection
(
const
QStringList
&
paths
=
BAE
::
defaultSources
,
std
::
function
<
void
(
uint
)
>
cb
=
nullptr
);
void
runBrain
();
public:
explicit
vvave
(
QObject
*
parent
=
nullptr
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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