Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liblinphone
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
10
Issues
10
List
Board
Labels
Milestones
Merge Requests
21
Merge Requests
21
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
BC
public
liblinphone
Commits
c20c54a2
Commit
c20c54a2
authored
Feb 14, 2018
by
Ronan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(MainDb): improve performance of selectSipAddressId and selectChatRoomId
parent
d0da718a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
14 deletions
+75
-14
abstract-db.cpp
src/db/abstract/abstract-db.cpp
+1
-0
main-db-p.h
src/db/main-db-p.h
+6
-4
main-db.cpp
src/db/main-db.cpp
+68
-10
No files found.
src/db/abstract/abstract-db.cpp
View file @
c20c54a2
...
...
@@ -92,6 +92,7 @@ bool AbstractDb::forceReconnect () {
try
{
lInfo
()
<<
"Reconnect... Try: "
<<
i
;
session
->
reconnect
();
init
();
lInfo
()
<<
"Database reconnection successful!"
;
return
true
;
}
catch
(
const
soci
::
soci_error
&
e
)
{
...
...
src/db/main-db-p.h
View file @
c20c54a2
...
...
@@ -28,20 +28,22 @@
// =============================================================================
namespace
soci
{
class
row
;
}
LINPHONE_BEGIN_NAMESPACE
class
Content
;
class
MainDbPrivate
:
public
AbstractDbPrivate
{
public
:
struct
Statements
;
mutable
std
::
unordered_map
<
long
long
,
std
::
weak_ptr
<
EventLog
>>
storageIdToEvent
;
mutable
std
::
unordered_map
<
long
long
,
std
::
weak_ptr
<
ChatMessage
>>
storageIdToChatMessage
;
private
:
std
::
unique_ptr
<
Statements
>
statements
;
void
initStatements
();
// ---------------------------------------------------------------------------
// Low level API.
// ---------------------------------------------------------------------------
...
...
src/db/main-db.cpp
View file @
c20c54a2
...
...
@@ -281,6 +281,59 @@ static constexpr string &blobToString (string &in) {
return
in
;
}
// -----------------------------------------------------------------------------
// Statements and helpers.
// -----------------------------------------------------------------------------
class
StatementBind
{
public
:
StatementBind
(
soci
::
statement
&
stmt
)
:
mStmt
(
stmt
)
{}
~
StatementBind
()
{
mStmt
.
bind_clean_up
();
}
template
<
typename
T
>
void
bind
(
const
T
&
var
,
const
char
*
name
)
{
mStmt
.
exchange
(
soci
::
use
(
var
,
name
));
}
template
<
typename
T
>
void
bindResult
(
T
&
var
)
{
mStmt
.
exchange
(
soci
::
into
(
var
));
}
bool
exec
()
{
mStmt
.
define_and_bind
();
return
mStmt
.
execute
(
true
);
}
private
:
soci
::
statement
&
mStmt
;
};
static
inline
unique_ptr
<
soci
::
statement
>
makeStatement
(
soci
::
session
&
session
,
const
char
*
stmt
)
{
return
makeUnique
<
soci
::
statement
>
(
session
.
prepare
<<
stmt
);
}
struct
MainDbPrivate
::
Statements
{
typedef
unique_ptr
<
soci
::
statement
>
Statement
;
Statement
selectSipAddressId
;
Statement
selectChatRoomId
;
};
void
MainDbPrivate
::
initStatements
()
{
soci
::
session
*
session
=
dbSession
.
getBackendSession
();
statements
=
makeUnique
<
Statements
>
();
statements
->
selectSipAddressId
=
makeStatement
(
*
session
,
"SELECT id FROM sip_address WHERE value = :sipAddress"
);
statements
->
selectChatRoomId
=
makeStatement
(
*
session
,
"SELECT id FROM chat_room WHERE peer_sip_address_id = :peerSipAddressId AND local_sip_address_id = :localSipAddressId"
);
}
// -----------------------------------------------------------------------------
long
long
MainDbPrivate
::
insertSipAddress
(
const
string
&
sipAddress
)
{
...
...
@@ -481,21 +534,24 @@ void MainDbPrivate::insertChatMessageParticipant (long long eventId, long long s
// -----------------------------------------------------------------------------
long
long
MainDbPrivate
::
selectSipAddressId
(
const
string
&
sipAddress
)
const
{
soci
::
session
*
session
=
dbSession
.
getBackendSession
();
long
long
id
;
*
session
<<
"SELECT id FROM sip_address WHERE value = :sipAddress"
,
soci
::
use
(
sipAddress
),
soci
::
into
(
id
);
return
session
->
got_data
()
?
id
:
-
1
;
StatementBind
stmt
(
*
statements
->
selectSipAddressId
);
stmt
.
bind
(
sipAddress
,
"sipAddress"
);
stmt
.
bindResult
(
id
);
return
stmt
.
exec
()
?
id
:
-
1
;
}
long
long
MainDbPrivate
::
selectChatRoomId
(
long
long
peerSipAddressId
,
long
long
localSipAddressId
)
const
{
soci
::
session
*
session
=
dbSession
.
getBackendSession
();
long
long
id
;
*
session
<<
"SELECT id FROM chat_room"
" WHERE peer_sip_address_id = :peerSipAddressId AND local_sip_address_id = :localSipAddressId"
,
soci
::
use
(
peerSipAddressId
),
soci
::
use
(
localSipAddressId
),
soci
::
into
(
id
);
return
session
->
got_data
()
?
id
:
-
1
;
StatementBind
stmt
(
*
statements
->
selectChatRoomId
);
stmt
.
bind
(
peerSipAddressId
,
"peerSipAddressId"
);
stmt
.
bind
(
localSipAddressId
,
"localSipAddressId"
);
stmt
.
bindResult
(
id
);
return
stmt
.
exec
()
?
id
:
-
1
;
}
long
long
MainDbPrivate
::
selectChatRoomId
(
const
ChatRoomId
&
chatRoomId
)
const
{
...
...
@@ -1768,6 +1824,8 @@ void MainDb::init () {
d
->
updateModuleVersion
(
"events"
,
ModuleVersionEvents
);
d
->
updateModuleVersion
(
"friends"
,
ModuleVersionFriends
);
d
->
initStatements
();
}
bool
MainDb
::
addEvent
(
const
shared_ptr
<
EventLog
>
&
eventLog
)
{
...
...
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