Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
biboumi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
88
Issues
88
List
Boards
Labels
Service Desk
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
biboumi
Commits
655151d8
Commit
655151d8
authored
Aug 26, 2017
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache the encoding_in database value, to avoid doing a query for each message
parent
1997fb5c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
7 deletions
+40
-7
src/bridge/bridge.cpp
src/bridge/bridge.cpp
+2
-5
src/database/database.cpp
src/database/database.cpp
+1
-0
src/database/database.hpp
src/database/database.hpp
+35
-0
src/xmpp/biboumi_adhoc_commands.cpp
src/xmpp/biboumi_adhoc_commands.cpp
+2
-2
No files found.
src/bridge/bridge.cpp
View file @
655151d8
...
...
@@ -22,15 +22,12 @@ static std::string in_encoding_for(const Bridge& bridge, const Iid& iid)
{
#ifdef USE_DATABASE
const
auto
jid
=
bridge
.
get_bare_jid
();
auto
options
=
Database
::
get_irc_channel_options_with_server_default
(
jid
,
iid
.
get_server
(),
iid
.
get_local
());
auto
result
=
options
.
col
<
Database
::
EncodingIn
>
();
if
(
!
result
.
empty
())
return
result
;
return
Database
::
get_encoding_in
(
jid
,
iid
.
get_server
(),
iid
.
get_local
());
#else
(
void
)
bridge
;
(
void
)
iid
;
#endif
return
{
"ISO-8859-1"
};
#endif
}
Bridge
::
Bridge
(
std
::
string
user_jid
,
BiboumiComponent
&
xmpp
,
std
::
shared_ptr
<
Poller
>&
poller
)
:
...
...
src/database/database.cpp
View file @
655151d8
...
...
@@ -14,6 +14,7 @@ Database::GlobalOptionsTable Database::global_options("GlobalOptions_");
Database
::
IrcServerOptionsTable
Database
::
irc_server_options
(
"IrcServerOptions_"
);
Database
::
IrcChannelOptionsTable
Database
::
irc_channel_options
(
"IrcChannelOptions_"
);
Database
::
RosterTable
Database
::
roster
(
"roster"
);
std
::
map
<
Database
::
CacheKey
,
Database
::
EncodingIn
::
real_type
>
Database
::
encoding_in_cache
{};
void
Database
::
open
(
const
std
::
string
&
filename
)
...
...
src/database/database.hpp
View file @
655151d8
...
...
@@ -13,6 +13,7 @@
#include <string>
#include <memory>
#include <map>
class
Database
...
...
@@ -140,7 +141,41 @@ class Database
static
RosterTable
roster
;
static
sqlite3
*
db
;
/**
* Some caches, to avoid doing very frequent query requests for a few options.
*/
using
CacheKey
=
std
::
tuple
<
std
::
string
,
std
::
string
,
std
::
string
>
;
static
EncodingIn
::
real_type
get_encoding_in
(
const
std
::
string
&
owner
,
const
std
::
string
&
server
,
const
std
::
string
&
channel
)
{
CacheKey
channel_key
{
owner
,
server
,
channel
};
auto
it
=
Database
::
encoding_in_cache
.
find
(
channel_key
);
if
(
it
==
Database
::
encoding_in_cache
.
end
())
{
auto
options
=
Database
::
get_irc_channel_options_with_server_default
(
owner
,
server
,
channel
);
EncodingIn
::
real_type
result
=
options
.
col
<
Database
::
EncodingIn
>
();
if
(
result
.
empty
())
result
=
"ISO-8859-1"
;
it
=
Database
::
encoding_in_cache
.
insert
(
std
::
make_pair
(
channel_key
,
result
)).
first
;
}
return
it
->
second
;
}
static
void
invalidate_encoding_in_cache
(
const
std
::
string
&
owner
,
const
std
::
string
&
server
,
const
std
::
string
&
channel
)
{
CacheKey
channel_key
{
owner
,
server
,
channel
};
Database
::
encoding_in_cache
.
erase
(
channel_key
);
}
static
void
invalidate_encoding_in_cache
()
{
Database
::
encoding_in_cache
.
clear
();
}
private:
static
std
::
string
gen_uuid
();
static
std
::
map
<
CacheKey
,
EncodingIn
::
real_type
>
encoding_in_cache
;
};
#endif
/* USE_DATABASE */
src/xmpp/biboumi_adhoc_commands.cpp
View file @
655151d8
...
...
@@ -430,7 +430,7 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com
options
.
col
<
Database
::
EncodingIn
>
()
=
value
->
get_inner
();
}
Database
::
invalidate_encoding_in_cache
();
options
.
save
(
Database
::
db
);
command_node
.
delete_all_children
();
...
...
@@ -599,7 +599,7 @@ bool handle_irc_channel_configuration_form(XmppComponent& xmpp_component, const
}
}
Database
::
invalidate_encoding_in_cache
(
requester
.
bare
(),
iid
.
get_server
(),
iid
.
get_local
());
options
.
save
(
Database
::
db
);
}
return
true
;
...
...
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