Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
a01ed064
Commit
a01ed064
authored
Oct 22, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fast identifier search for Doctrine_Hydrate, now the hydration should run in O(1) instead of O(n)
parent
6ed2e63d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
29 deletions
+57
-29
Collection.php
lib/Doctrine/Collection.php
+18
-1
Hydrate.php
lib/Doctrine/Hydrate.php
+29
-11
Array.php
lib/Doctrine/Hydrate/Array.php
+5
-15
Record.php
lib/Doctrine/Hydrate/Record.php
+5
-2
No files found.
lib/Doctrine/Collection.php
View file @
a01ed064
...
...
@@ -235,7 +235,24 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
{
return
end
(
$this
->
data
);
}
/**
* returns the last record in the collection
*
* @return mixed
*/
public
function
end
()
{
return
end
(
$this
->
data
);
}
/**
* returns the current key
*
* @return mixed
*/
public
function
key
()
{
return
key
(
$this
->
data
);
}
/**
* setReference
* sets a reference pointer
...
...
lib/Doctrine/Hydrate.php
View file @
a01ed064
...
...
@@ -1059,6 +1059,10 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
foreach
(
$this
->
_aliasMap
as
$alias
=>
$data
)
{
$componentName
=
$data
[
'table'
]
->
getComponentName
();
$listeners
[
$componentName
]
=
$data
[
'table'
]
->
getRecordListener
();
$identifierMap
[
$alias
]
=
array
();
$currData
[
$alias
]
=
array
();
$prev
[
$alias
]
=
array
();
$id
[
$alias
]
=
''
;
}
while
(
$data
=
$stmt
->
fetch
(
Doctrine
::
FETCH_ASSOC
))
{
...
...
@@ -1076,7 +1080,6 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
$cache
[
$key
][
'alias'
]
=
$this
->
_tableAliases
[
strtolower
(
implode
(
'__'
,
$e
))];
}
$map
=
$this
->
_aliasMap
[
$cache
[
$key
][
'alias'
]];
$table
=
$map
[
'table'
];
$alias
=
$cache
[
$key
][
'alias'
];
...
...
@@ -1087,21 +1090,17 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
}
if
(
!
isset
(
$currData
[
$alias
]))
{
$currData
[
$alias
]
=
array
();
}
if
(
!
isset
(
$prev
[
$alias
]))
{
$prev
[
$alias
]
=
array
();
if
(
$table
->
isIdentifier
(
$field
))
{
$id
[
$alias
]
.=
'|'
.
$value
;
}
$currData
[
$alias
][
$field
]
=
$table
->
prepareValue
(
$field
,
$value
);
if
(
$value
!==
null
)
{
$identifiable
[
$alias
]
=
true
;
}
}
// dealing with root component
$table
=
$this
->
_aliasMap
[
$rootAlias
][
'table'
];
$componentName
=
$table
->
getComponentName
();
...
...
@@ -1111,8 +1110,13 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
$oneToOne
=
false
;
$index
=
$isSimpleQuery
?
false
:
$driver
->
search
(
$element
,
$array
);
if
(
$isSimpleQuery
)
{
$index
=
false
;
}
else
{
$index
=
isset
(
$identifierMap
[
$rootAlias
][
$id
[
$rootAlias
]])
?
$identifierMap
[
$rootAlias
][
$id
[
$rootAlias
]]
:
false
;
}
if
(
$index
===
false
)
{
$event
->
set
(
'data'
,
$element
);
$listeners
[
$componentName
]
->
postHydrate
(
$event
);
...
...
@@ -1132,7 +1136,10 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
}
else
{
$array
[]
=
$element
;
}
$identifierMap
[
$rootAlias
][
$id
[
$rootAlias
]]
=
$driver
->
getLastKey
(
$array
);
}
$this
->
_setLastElement
(
$prev
,
$array
,
$index
,
$rootAlias
,
$oneToOne
);
unset
(
$currData
[
$rootAlias
]);
...
...
@@ -1150,6 +1157,8 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
$relation
=
$map
[
'relation'
];
$componentAlias
=
$map
[
'relation'
]
->
getAlias
();
$path
=
$parent
.
'.'
.
$alias
;
if
(
!
isset
(
$prev
[
$parent
]))
{
break
;
}
...
...
@@ -1162,7 +1171,12 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
// append element
if
(
isset
(
$identifiable
[
$alias
]))
{
$index
=
$isSimpleQuery
?
false
:
$driver
->
search
(
$element
,
$prev
[
$parent
][
$componentAlias
]);
if
(
$isSimpleQuery
)
{
$index
=
false
;
}
else
{
$index
=
isset
(
$identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$alias
]])
?
$identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$alias
]]
:
false
;
}
if
(
$index
===
false
)
{
$event
->
set
(
'data'
,
$element
);
...
...
@@ -1180,6 +1194,8 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
}
else
{
$prev
[
$parent
][
$componentAlias
][]
=
$element
;
}
$identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$alias
]]
=
$driver
->
getLastKey
(
$prev
[
$parent
][
$componentAlias
]);
}
}
// register collection for later snapshots
...
...
@@ -1195,7 +1211,9 @@ class Doctrine_Hydrate extends Doctrine_Locator_Injectable implements Serializab
}
$coll
=&
$prev
[
$parent
][
$componentAlias
];
$this
->
_setLastElement
(
$prev
,
$coll
,
$index
,
$alias
,
$oneToOne
);
$id
[
$alias
]
=
''
;
}
$id
[
$rootAlias
]
=
''
;
}
$driver
->
flush
();
...
...
lib/Doctrine/Hydrate/Array.php
View file @
a01ed064
...
...
@@ -60,24 +60,14 @@ class Doctrine_Hydrate_Array
{
return
null
;
}
public
function
search
(
array
$element
,
array
$data
)
public
function
getLastKey
(
&
$data
)
{
foreach
(
$data
as
$key
=>
$val
)
{
$found
=
true
;
foreach
(
$element
as
$k
=>
$e
)
{
if
(
isset
(
$val
[
$k
])
&&
$val
[
$k
]
!==
$e
)
{
$found
=
false
;
break
;
}
}
if
(
$found
)
{
return
$key
;
}
}
return
false
;
end
(
$data
);
return
key
(
$data
);
}
public
function
flush
()
{
}
}
\ No newline at end of file
}
lib/Doctrine/Hydrate/Record.php
View file @
a01ed064
...
...
@@ -46,9 +46,12 @@ class Doctrine_Hydrate_Record extends Doctrine_Locator_Injectable
return
$coll
;
}
public
function
search
(
Doctrine_Record
$record
,
Doctrine_Collection
$coll
)
public
function
getLastKey
(
$coll
)
{
return
array_search
(
$record
,
$coll
->
getData
(),
true
);
$coll
->
end
();
return
$coll
->
key
();
}
public
function
initRelated
(
$record
,
$name
)
{
...
...
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