Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
mobile Datovka
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Packages
Packages
Container Registry
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Datovka projects
mobile Datovka
Commits
7ea3b201
Commit
7ea3b201
authored
Oct 10, 2017
by
Martin Straka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code refactoring
parent
de0ee1c9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
41 deletions
+37
-41
src/net/db_wrapper.cpp
src/net/db_wrapper.cpp
+1
-1
src/net/xml_layer.h
src/net/xml_layer.h
+0
-1
src/sqlite/zfo_db.cpp
src/sqlite/zfo_db.cpp
+28
-32
src/sqlite/zfo_db.h
src/sqlite/zfo_db.h
+4
-3
src/zfo.cpp
src/zfo.cpp
+1
-1
src/zfo.h
src/zfo.h
+3
-3
No files found.
src/net/db_wrapper.cpp
View file @
7ea3b201
...
...
@@ -342,5 +342,5 @@ bool DbWrapper::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
const
QByteArray
&
zfoData
)
{
return
globZfoDbPtr
->
insertZfoToDb
(
msgId
,
isTestAccount
,
zfoSize
,
zfoData
.
toBase64
());
zfoData
.
toBase64
()
,
(
globSet
.
zfoDbSizeMBs
*
1000000
)
);
}
src/net/xml_layer.h
View file @
7ea3b201
...
...
@@ -286,7 +286,6 @@ public:
* @param[out] fileList List of files structure.
* @param[out] txt Error description if something failed.
* @param[out] zfoData ZFO file content.
*
* @return true if success.
*/
static
...
...
src/sqlite/zfo_db.cpp
View file @
7ea3b201
...
...
@@ -24,7 +24,6 @@
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QObject>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
...
...
@@ -35,7 +34,6 @@
#include "src/sqlite/db_tables.h"
#include "src/sqlite/dbs.h"
#include "src/sqlite/zfo_db.h"
#include "src/settings.h"
ZfoDb
::
ZfoDb
(
const
QString
&
connectionName
)
:
SQLiteDb
(
connectionName
)
...
...
@@ -65,7 +63,7 @@ bool ZfoDb::openDb(const QString &fileName, bool storeToDisk)
QString
queryStr
=
"SELECT count(*) FROM zfo_size_cnt"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
goto
fail
;
}
...
...
@@ -75,7 +73,7 @@ bool ZfoDb::openDb(const QString &fileName, bool storeToDisk)
queryStr
=
"INSERT INTO zfo_size_cnt (id,totalSize) "
"VALUES (0,0)"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
goto
fail
;
}
...
...
@@ -83,7 +81,7 @@ bool ZfoDb::openDb(const QString &fileName, bool storeToDisk)
}
return
true
;
}
else
{
q
Debug
()
<<
q
Critical
()
<<
"Cannot execute SQL query and/or read SQL data: %s."
,
query
.
lastError
().
text
().
toUtf8
().
constData
();
}
...
...
@@ -251,21 +249,21 @@ void ZfoDb::deleteZfo(qint64 msgId, bool isTestAccount, int zfoSize)
QString
queryStr
=
"DELETE FROM message_zfos WHERE "
"dmID = :msgId AND testEnv = :isTestAccount"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
;
}
query
.
bindValue
(
":msgId"
,
msgId
);
query
.
bindValue
(
":isTestAccount"
,
isTestAccount
);
if
(
!
query
.
exec
())
{
q
Debug
()
<<
"Cannot execute SQL query:"
<<
q
Critical
()
<<
"Cannot execute SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
}
queryStr
=
"UPDATE zfo_size_cnt SET totalSize = totalSize - :zfoSize"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
;
}
...
...
@@ -273,7 +271,7 @@ void ZfoDb::deleteZfo(qint64 msgId, bool isTestAccount, int zfoSize)
query
.
bindValue
(
":zfoSize"
,
zfoSize
);
if
(
!
query
.
exec
())
{
q
Debug
()
<<
"Cannot execute SQL query:"
<<
q
Critical
()
<<
"Cannot execute SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
}
}
...
...
@@ -285,7 +283,7 @@ QByteArray ZfoDb::getZfoContentFromDb(qint64 msgId, bool isTestAccount)
QString
queryStr
=
"SELECT data FROM message_zfos WHERE "
"dmID = :msgId AND testEnv = :isTestAccount"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
goto
fail
;
}
...
...
@@ -307,7 +305,7 @@ int ZfoDb::getZfoSizeFromDb(qint64 msgId, bool isTestAccount)
QString
queryStr
=
"SELECT size FROM message_zfos WHERE "
"dmID = :msgId AND testEnv = :isTestAccount"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
goto
fail
;
}
...
...
@@ -323,7 +321,7 @@ fail:
}
bool
ZfoDb
::
insertZfoToDb
(
qint64
msgId
,
bool
isTestAccount
,
int
zfoSize
,
const
QByteArray
&
zfoData
)
const
QByteArray
&
zfoData
,
unsigned
int
sizeLimit
)
{
QSqlQuery
query
(
m_db
);
qint64
lastAccessTime
=
-
1
;
...
...
@@ -331,7 +329,7 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
QString
queryStr
=
"SELECT lastAccessTime FROM message_zfos WHERE "
"dmID = :msgId AND testEnv = :isTestAccount"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
false
;
}
...
...
@@ -343,7 +341,7 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
lastAccessTime
=
query
.
value
(
0
).
toLongLong
();
}
}
else
{
q
Debug
()
<<
"Cannot execute SQL query:"
<<
q
Critical
()
<<
"Cannot execute SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
false
;
}
...
...
@@ -355,7 +353,7 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
"size = :zfoSize, data = :zfoData "
"WHERE dmID = :msgId AND testEnv = :isTestAccount"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
false
;
}
...
...
@@ -365,7 +363,7 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
query
.
bindValue
(
":zfoSize"
,
zfoSize
);
query
.
bindValue
(
":zfoData"
,
zfoData
);
if
(
!
query
.
exec
())
{
q
Debug
()
<<
"Cannot execute SQL query:"
<<
q
Critical
()
<<
"Cannot execute SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
false
;
}
...
...
@@ -374,10 +372,8 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
/* ZFO is not in the databse = insert and release db size if needed */
// compute database size with new zfo
uint
maximalSize
=
(
globSet
.
zfoDbSizeMBs
*
1000000
)
-
zfoSize
;
// if database is exceeded, release some oldest zfo files (based on size)
if
(
isDbSizeExceeded
(
maximal
Size
))
{
if
(
isDbSizeExceeded
(
sizeLimit
-
zfo
Size
))
{
releaseDb
(
zfoSize
);
}
...
...
@@ -386,7 +382,7 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
":msgId, :isTestAccount, :downloadTime, :zfoSize, :zfoData)"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
false
;
}
...
...
@@ -398,7 +394,7 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
query
.
bindValue
(
":zfoData"
,
zfoData
);
if
(
!
query
.
exec
())
{
q
Debug
()
<<
"Cannot execute SQL query:"
<<
q
Critical
()
<<
"Cannot execute SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
false
;
}
...
...
@@ -407,7 +403,7 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
queryStr
=
"UPDATE zfo_size_cnt SET totalSize = totalSize + :zfoSize"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
false
;
}
...
...
@@ -415,7 +411,7 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
query
.
bindValue
(
":zfoSize"
,
zfoSize
);
if
(
!
query
.
exec
())
{
q
Debug
()
<<
"Cannot execute SQL query:"
<<
q
Critical
()
<<
"Cannot execute SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
false
;
}
...
...
@@ -423,13 +419,13 @@ bool ZfoDb::insertZfoToDb(qint64 msgId, bool isTestAccount, int zfoSize,
return
true
;
}
bool
ZfoDb
::
isDbSizeExceeded
(
uint
currentLimit
)
bool
ZfoDb
::
isDbSizeExceeded
(
u
nsigned
int
currentLimit
)
{
QSqlQuery
query
(
m_db
);
QString
queryStr
=
"SELECT totalSize FROM zfo_size_cnt WHERE id = :id"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
false
;
}
...
...
@@ -438,7 +434,7 @@ bool ZfoDb::isDbSizeExceeded(uint currentLimit)
query
.
first
()
&&
query
.
isValid
())
{
return
(
currentLimit
<
query
.
value
(
0
).
toUInt
());
}
else
{
q
Debug
()
<<
"Cannot execute SQL query:"
<<
q
Critical
()
<<
"Cannot execute SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
}
...
...
@@ -454,7 +450,7 @@ void ZfoDb::updateZfoLastAccessTime(qint64 msgId, bool isTestAccount)
"WHERE dmID = :msgId AND testEnv = :isTestAccount"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
return
;
}
...
...
@@ -464,20 +460,20 @@ void ZfoDb::updateZfoLastAccessTime(qint64 msgId, bool isTestAccount)
query
.
bindValue
(
":newTime"
,
QDateTime
::
currentSecsSinceEpoch
());
if
(
!
query
.
exec
())
{
q
Debug
()
<<
"Cannot execute SQL query:"
<<
q
Critical
()
<<
"Cannot execute SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
}
}
bool
ZfoDb
::
releaseDb
(
uint
releaseSpace
)
bool
ZfoDb
::
releaseDb
(
u
nsigned
int
releaseSpace
)
{
QSqlQuery
query
(
m_db
);
uint
releasedBytes
=
0
;
u
nsigned
int
releasedBytes
=
0
;
QString
queryStr
=
"SELECT dmId, testEnv, size, lastAccessTime "
"FROM message_zfos ORDER BY lastAccessTime ASC"
;
if
(
!
query
.
prepare
(
queryStr
))
{
q
Debug
()
<<
"Cannot prepare SQL query:"
<<
q
Critical
()
<<
"Cannot prepare SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
goto
fail
;
}
...
...
@@ -497,7 +493,7 @@ bool ZfoDb::releaseDb(uint releaseSpace)
query
.
next
();
}
}
else
{
q
Debug
()
<<
"Cannot execute SQL query:"
<<
q
Critical
()
<<
"Cannot execute SQL query:"
<<
query
.
lastError
().
text
().
toUtf8
().
constData
();
goto
fail
;
}
...
...
src/sqlite/zfo_db.h
View file @
7ea3b201
...
...
@@ -127,10 +127,11 @@ public:
* @param[in] isTestAccount True if account is ISDS testing.
* @param[in] zfoSize Real size of zfo.
* @param[in] zfoBase64Data Zfo data in base64.
* @param[in] sizeLimit Zfo database size limit in bytes.
* @return true if success.
*/
bool
insertZfoToDb
(
qint64
msgId
,
bool
isTestAccount
,
int
zfoSize
,
const
QByteArray
&
zfoBase64Data
);
const
QByteArray
&
zfoBase64Data
,
unsigned
int
sizeLimit
);
/*!
* @brief Test if is zfo database size exceeded.
...
...
@@ -138,7 +139,7 @@ public:
* @param[in] currentLimit Current database size limit.
* @return True if db size is exceeded.
*/
bool
isDbSizeExceeded
(
uint
currentLimit
);
bool
isDbSizeExceeded
(
u
nsigned
int
currentLimit
);
/*!
* @brief Release db - delete oldest zfo files and vacuum db.
...
...
@@ -146,7 +147,7 @@ public:
* @param[in] releaseSpace How many bytes should be released.
* @return True true if success.
*/
bool
releaseDb
(
uint
releaseSpace
);
bool
releaseDb
(
u
nsigned
int
releaseSpace
);
/*!
* @brief Update Zfo last access time.
...
...
src/zfo.cpp
View file @
7ea3b201
...
...
@@ -33,7 +33,7 @@ int Zfo::getZfoSizeFromDb(qint64 msgId, bool isTestAccount)
return
globZfoDbPtr
->
getZfoSizeFromDb
(
msgId
,
isTestAccount
);
}
void
Zfo
::
reduceZfoDbSize
(
uint
releaseSpaceInMB
)
void
Zfo
::
reduceZfoDbSize
(
u
nsigned
int
releaseSpaceInMB
)
{
// convert MBs from QML to bytes for database resize operation
globZfoDbPtr
->
releaseDb
(
releaseSpaceInMB
*
1000000
);
...
...
src/zfo.h
View file @
7ea3b201
...
...
@@ -48,7 +48,7 @@ public:
* @param[in] isTestAccount True if account is in the ISDS testing environment.
* @return Size of zfo file in bytes.
*/
Q_INVOKABLE
Q_INVOKABLE
static
int
getZfoSizeFromDb
(
qint64
msgId
,
bool
isTestAccount
);
/*!
...
...
@@ -56,8 +56,8 @@ public:
*
* @param[in] releaseSpaceInMB How many mega bytes should be released.
*/
Q_INVOKABLE
void
reduceZfoDbSize
(
uint
releaseSpaceInMB
);
Q_INVOKABLE
static
void
reduceZfoDbSize
(
u
nsigned
int
releaseSpaceInMB
);
};
#endif // ZFO_H
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