Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
GLPI
glpi
Commits
4beca992
Commit
4beca992
authored
Apr 30, 2019
by
Cédric Anne
Committed by
Johan Cwiklinski
May 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cache on AbstractDatabase::tableExists()
parent
3f8456dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
13 deletions
+27
-13
install/update.php
install/update.php
+1
-1
src/Glpi/Database/AbstractDatabase.php
src/Glpi/Database/AbstractDatabase.php
+24
-10
tests/units/Migration.php
tests/units/Migration.php
+2
-2
No files found.
install/update.php
View file @
4beca992
...
...
@@ -47,7 +47,7 @@ $GLPI = new GLPI();
$GLPI
->
initLogger
();
$DB
=
\
Glpi\DatabaseFactory
::
create
();
$DB
->
disableTableCaching
();
//prevents issues on fieldExists upgrading from old versions
$DB
->
disableTableCaching
();
//prevents issues on
table/
fieldExists upgrading from old versions
$update
=
new
Update
(
$DB
);
$update
->
initSession
();
...
...
src/Glpi/Database/AbstractDatabase.php
View file @
4beca992
...
...
@@ -726,22 +726,36 @@ abstract class AbstractDatabase
* Check if a table exists
*
* @since 9.2
* @since 10.0 Added $usecache parameter.
*
* @param string $tablename Table name
* @param string $tablename Table name
* @param boolean $usecache If use table list cache
*
* @return boolean
*/
public
function
tableExists
(
string
$tablename
):
bool
public
function
tableExists
(
string
$tablename
,
$usecache
=
true
):
bool
{
// Get a list of tables contained within the database.
$result
=
$this
->
listTables
(
"%
$tablename
%"
);
static
$table_cache
=
[];
if
(
!
$this
->
cache_disabled
&&
$usecache
&&
in_array
(
$tablename
,
$table_cache
))
{
return
true
;
}
if
(
count
(
$result
))
{
while
(
$data
=
$result
->
next
())
{
if
(
$data
[
'TABLE_NAME'
]
===
$tablename
)
{
return
true
;
}
}
// Retrieve all tables if cache is empty but enabled, in order to fill cache
// with all known tables
$retrieve_all
=
!
$this
->
cache_disabled
&&
empty
(
$table_cache
);
$result
=
$this
->
listTables
(
$retrieve_all
?
'glpi_%'
:
$tablename
);
$found_tables
=
[];
while
(
$data
=
$result
->
next
())
{
$found_tables
[]
=
$data
[
'TABLE_NAME'
];
}
if
(
!
$this
->
cache_disabled
)
{
$table_cache
=
array_unique
(
array_merge
(
$table_cache
,
$found_tables
));
}
if
(
in_array
(
$tablename
,
$found_tables
))
{
return
true
;
}
return
false
;
...
...
tests/units/Migration.php
View file @
4beca992
...
...
@@ -292,8 +292,8 @@ class Migration extends \GLPITestCase {
' AND `table_type` = ? AND `table_name` LIKE ?'
]);
$this
->
array
(
$this
->
qry_params
)
->
isIdenticalTo
([
0
=>
[
$DB
->
dbdefault
,
'BASE TABLE'
,
'
%
table1
%
'
],
1
=>
[
$DB
->
dbdefault
,
'BASE TABLE'
,
'
%
table2
%
'
]
0
=>
[
$DB
->
dbdefault
,
'BASE TABLE'
,
'table1'
],
1
=>
[
$DB
->
dbdefault
,
'BASE TABLE'
,
'table2'
]
]);
//try to backup existant tables
...
...
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