Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
348d0c94
Commit
348d0c94
authored
Jan 10, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stats: lazy initialization
Ask the DatabasePlugin for stats when the first client requests them, not at startup.
parent
e9ba5fca
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
11 deletions
+37
-11
DatabaseGlue.cxx
src/DatabaseGlue.cxx
+0
-2
Stats.cxx
src/Stats.cxx
+34
-7
Stats.hxx
src/Stats.hxx
+2
-1
UpdateGlue.cxx
src/UpdateGlue.cxx
+1
-1
No files found.
src/DatabaseGlue.cxx
View file @
348d0c94
...
...
@@ -137,8 +137,6 @@ DatabaseGlobalOpen(Error &error)
db_is_open
=
true
;
stats_update
();
return
true
;
}
...
...
src/Stats.cxx
View file @
348d0c94
...
...
@@ -39,6 +39,12 @@ static unsigned start_time;
static
DatabaseStats
stats
;
enum
class
StatsValidity
:
uint8_t
{
INVALID
,
VALID
,
FAILED
,
};
static
StatsValidity
stats_validity
=
StatsValidity
::
INVALID
;
void
stats_global_init
(
void
)
{
#ifndef WIN32
...
...
@@ -46,21 +52,39 @@ void stats_global_init(void)
#endif
}
void
stats_update
(
void
)
void
stats_invalidate
()
{
assert
(
GetDatabase
()
!=
nullptr
);
Error
error
;
stats_validity
=
StatsValidity
::
INVALID
;
}
static
bool
stats_update
()
{
switch
(
stats_validity
)
{
case
StatsValidity
:
:
INVALID
:
break
;
case
StatsValidity
:
:
VALID
:
return
true
;
case
StatsValidity
:
:
FAILED
:
return
false
;
}
DatabaseStats
stats2
;
Error
error
;
const
DatabaseSelection
selection
(
""
,
true
);
if
(
GetDatabase
()
->
GetStats
(
selection
,
stats2
,
error
))
{
stats
=
stats2
;
if
(
GetDatabase
()
->
GetStats
(
selection
,
stats
,
error
))
{
stats_validity
=
StatsValidity
::
VALID
;
return
true
;
}
else
{
LogError
(
error
);
stats
.
Clear
();
stats_validity
=
StatsValidity
::
FAILED
;
return
true
;
}
}
...
...
@@ -74,7 +98,10 @@ db_stats_print(Client &client)
database plugin */
/* TODO: move this into the "proxy" database plugin as
an "idle" handler */
stats_update
();
stats_invalidate
();
if
(
!
stats_update
())
return
;
client_printf
(
client
,
"artists: %u
\n
"
...
...
src/Stats.hxx
View file @
348d0c94
...
...
@@ -24,7 +24,8 @@ class Client;
void
stats_global_init
(
void
);
void
stats_update
(
void
);
void
stats_invalidate
();
void
stats_print
(
Client
&
client
);
...
...
src/UpdateGlue.cxx
View file @
348d0c94
...
...
@@ -163,7 +163,7 @@ static void update_finished_event(void)
}
else
{
progress
=
UPDATE_PROGRESS_IDLE
;
stats_
up
date
();
stats_
invali
date
();
}
}
...
...
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