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
84b65054
Commit
84b65054
authored
15 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
[premysl.vyhnal] optimize get_days_with_logs(). Fixes #4964
parent
2986ceb8
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
+7
-27
7 additions, 27 deletions
src/common/logger.py
with
7 additions
and
27 deletions
src/common/logger.py
+
7
−
27
View file @
84b65054
...
...
@@ -586,8 +586,12 @@ class Logger:
seconds_in_a_day
=
86400
# 60 * 60 * 24
last_second_of_month
=
start_of_month
+
(
seconds_in_a_day
*
max_day
)
-
1
# Select times and 'floor' them to time 0:00
# (by dividing, they are integers)
# and take only one of the same values (distinct)
# Now we have timestamps of time 0:00 of every day with logs
self
.
cur
.
execute
(
'''
SELECT
time
FROM logs
SELECT
DISTINCT time/(86400)*86400
FROM logs
WHERE (%s)
AND time BETWEEN %d AND %d
AND kind NOT IN (%d, %d)
...
...
@@ -596,34 +600,10 @@ class Logger:
constants
.
KIND_STATUS
,
constants
.
KIND_GCSTATUS
))
result
=
self
.
cur
.
fetchall
()
# Copy all interesting times in a temporary table
try
:
self
.
cur
.
execute
(
'
CREATE TEMPORARY TABLE temp_table(time,INTEGER)
'
)
except
sqlite
.
OperationalError
,
e
:
raise
exceptions
.
PysqliteOperationalError
(
str
(
e
))
# convert timestamps to day of month
for
line
in
result
:
self
.
cur
.
execute
(
'''
INSERT INTO temp_table (time) VALUES (%d)
'''
%
(
line
[
0
]))
# then search in this small temp table for each day
for
day
in
xrange
(
1
,
max_day
+
1
):
# count from 1 to 28 or to 30 or to 31
start_of_day
=
self
.
get_unix_time_from_date
(
year
,
month
,
day
)
last_second_of_day
=
start_of_day
+
seconds_in_a_day
-
1
days_with_logs
[
0
:
0
]
=
[
time
.
gmtime
(
line
[
0
])[
2
]]
# just ask one row to see if we have sth for this date
self
.
cur
.
execute
(
'''
SELECT time FROM temp_table
WHERE time BETWEEN %d AND %d
LIMIT 1
'''
%
(
start_of_day
,
last_second_of_day
))
result
=
self
.
cur
.
fetchone
()
if
result
:
days_with_logs
[
0
:
0
]
=
[
day
]
# Delete temporary table
self
.
cur
.
execute
(
'
DROP TABLE temp_table
'
)
result
=
self
.
cur
.
fetchone
()
return
days_with_logs
def
get_last_date_that_has_logs
(
self
,
jid
,
account
=
None
,
is_room
=
False
):
...
...
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