Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Weblate
gajim
Commits
134d55b2
Commit
134d55b2
authored
12 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
don't commit SQL request too fast to improve performences. Fixes #6905
parent
2fdbe37b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/common/logger.py
+30
-19
30 additions, 19 deletions
src/common/logger.py
with
30 additions
and
19 deletions
src/common/logger.py
+
30
−
19
View file @
134d55b2
...
@@ -34,6 +34,7 @@ import time
...
@@ -34,6 +34,7 @@ import time
import
datetime
import
datetime
from
gzip
import
GzipFile
from
gzip
import
GzipFile
from
cStringIO
import
StringIO
from
cStringIO
import
StringIO
import
gobject
import
exceptions
import
exceptions
import
gajim
import
gajim
...
@@ -106,6 +107,7 @@ class Logger:
...
@@ -106,6 +107,7 @@ class Logger:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
jids_already_in
=
[]
# holds jids that we already have in DB
self
.
jids_already_in
=
[]
# holds jids that we already have in DB
self
.
con
=
None
self
.
con
=
None
self
.
commit_timout_id
=
None
if
not
os
.
path
.
exists
(
LOG_DB_PATH
):
if
not
os
.
path
.
exists
(
LOG_DB_PATH
):
# this can happen only the first time (the time we create the db)
# this can happen only the first time (the time we create the db)
...
@@ -163,15 +165,25 @@ class Logger:
...
@@ -163,15 +165,25 @@ class Logger:
self
.
open_db
()
self
.
open_db
()
self
.
get_jids_already_in_db
()
self
.
get_jids_already_in_db
()
def
_really_commit
(
self
):
try
:
self
.
con
.
commit
()
except
sqlite
.
OperationalError
,
e
:
print
>>
sys
.
stderr
,
str
(
e
)
self
.
commit_timout_id
=
None
return
False
def
_timeout_commit
(
self
):
if
self
.
commit_timout_id
:
return
self
.
commit_timout_id
=
gobject
.
timeout_add
(
500
,
self
.
_really_commit
)
def
simple_commit
(
self
,
sql_to_commit
):
def
simple_commit
(
self
,
sql_to_commit
):
"""
"""
Helper to commit
Helper to commit
"""
"""
self
.
cur
.
execute
(
sql_to_commit
)
self
.
cur
.
execute
(
sql_to_commit
)
try
:
self
.
_timeout_commit
()
self
.
con
.
commit
()
except
sqlite
.
OperationalError
,
e
:
print
>>
sys
.
stderr
,
str
(
e
)
def
get_jids_already_in_db
(
self
):
def
get_jids_already_in_db
(
self
):
try
:
try
:
...
@@ -398,12 +410,14 @@ class Logger:
...
@@ -398,12 +410,14 @@ class Logger:
except
sqlite
.
OperationalError
,
e
:
except
sqlite
.
OperationalError
,
e
:
raise
exceptions
.
PysqliteOperationalError
(
str
(
e
))
raise
exceptions
.
PysqliteOperationalError
(
str
(
e
))
message_id
=
None
message_id
=
None
try
:
if
write_unread
:
self
.
con
.
commit
()
try
:
if
write_unread
:
self
.
con
.
commit
()
message_id
=
self
.
cur
.
lastrowid
message_id
=
self
.
cur
.
lastrowid
except
sqlite
.
OperationalError
,
e
:
except
sqlite
.
OperationalError
,
e
:
print
>>
sys
.
stderr
,
str
(
e
)
print
>>
sys
.
stderr
,
str
(
e
)
else
:
self
.
_timeout_commit
()
if
message_id
:
if
message_id
:
self
.
insert_unread_events
(
message_id
,
values
[
0
])
self
.
insert_unread_events
(
message_id
,
values
[
0
])
return
message_id
return
message_id
...
@@ -922,10 +936,7 @@ class Logger:
...
@@ -922,10 +936,7 @@ class Logger:
VALUES (?, ?, ?, ?);
VALUES (?, ?, ?, ?);
'''
,
(
hash_method
,
hash_
,
buffer
(
data
),
int
(
time
.
time
())))
'''
,
(
hash_method
,
hash_
,
buffer
(
data
),
int
(
time
.
time
())))
# (1) -- note above
# (1) -- note above
try
:
self
.
_timeout_commit
()
self
.
con
.
commit
()
except
sqlite
.
OperationalError
,
e
:
print
>>
sys
.
stderr
,
str
(
e
)
def
update_caps_time
(
self
,
method
,
hash_
):
def
update_caps_time
(
self
,
method
,
hash_
):
sql
=
'''
UPDATE caps_cache SET last_seen = %d
sql
=
'''
UPDATE caps_cache SET last_seen = %d
...
@@ -963,9 +974,9 @@ class Logger:
...
@@ -963,9 +974,9 @@ class Logger:
# Fill roster tables with the new roster
# Fill roster tables with the new roster
for
jid
in
roster
:
for
jid
in
roster
:
self
.
add_or_update_contact
(
account_jid
,
jid
,
roster
[
jid
][
'
name
'
],
self
.
add_or_update_contact
(
account_jid
,
jid
,
roster
[
jid
][
'
name
'
],
roster
[
jid
][
'
subscription
'
],
roster
[
jid
][
'
ask
'
],
roster
[
jid
][
'
subscription
'
],
roster
[
jid
][
'
ask
'
],
roster
[
jid
][
'
groups
'
],
commit
=
False
)
roster
[
jid
][
'
groups
'
],
commit
=
False
)
self
.
con
.
commit
()
self
.
_timeout_
commit
()
# At this point, we are sure the replacement works properly so we can
# At this point, we are sure the replacement works properly so we can
# set the new roster_version value.
# set the new roster_version value.
...
@@ -987,7 +998,7 @@ class Logger:
...
@@ -987,7 +998,7 @@ class Logger:
self
.
cur
.
execute
(
self
.
cur
.
execute
(
'
DELETE FROM roster_entry WHERE account_jid_id=? AND jid_id=?
'
,
'
DELETE FROM roster_entry WHERE account_jid_id=? AND jid_id=?
'
,
(
account_jid_id
,
jid_id
))
(
account_jid_id
,
jid_id
))
self
.
con
.
commit
()
self
.
_timeout_
commit
()
def
add_or_update_contact
(
self
,
account_jid
,
jid
,
name
,
sub
,
ask
,
groups
,
def
add_or_update_contact
(
self
,
account_jid
,
jid
,
name
,
sub
,
ask
,
groups
,
commit
=
True
):
commit
=
True
):
...
@@ -1022,7 +1033,7 @@ class Logger:
...
@@ -1022,7 +1033,7 @@ class Logger:
self
.
convert_human_subscription_values_to_db_api_values
(
sub
),
self
.
convert_human_subscription_values_to_db_api_values
(
sub
),
bool
(
ask
)))
bool
(
ask
)))
if
commit
:
if
commit
:
self
.
con
.
commit
()
self
.
_timeout_
commit
()
def
get_roster
(
self
,
account_jid
):
def
get_roster
(
self
,
account_jid
):
"""
"""
...
@@ -1075,7 +1086,7 @@ class Logger:
...
@@ -1075,7 +1086,7 @@ class Logger:
(
account_jid_id
,))
(
account_jid_id
,))
self
.
cur
.
execute
(
'
DELETE FROM roster_group WHERE account_jid_id=?
'
,
self
.
cur
.
execute
(
'
DELETE FROM roster_group WHERE account_jid_id=?
'
,
(
account_jid_id
,))
(
account_jid_id
,))
self
.
con
.
commit
()
self
.
_timeout_
commit
()
def
save_if_not_exists
(
self
,
with_
,
direction
,
tim
,
msg
=
''
,
nick
=
None
):
def
save_if_not_exists
(
self
,
with_
,
direction
,
tim
,
msg
=
''
,
nick
=
None
):
if
tim
:
if
tim
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment