Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Jan-Hendrik Willms
Stud.IP
Commits
2bbcfb7b
Commit
2bbcfb7b
authored
1 year ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
proposal for caching, re #3234
Merge request
studip/studip!2194
parent
9e3cfdbe
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/classes/StudipTreeNodeCachableTrait.php
+59
-0
59 additions, 0 deletions
lib/classes/StudipTreeNodeCachableTrait.php
lib/models/RangeTreeNode.php
+5
-13
5 additions, 13 deletions
lib/models/RangeTreeNode.php
lib/models/StudipStudyArea.class.php
+6
-12
6 additions, 12 deletions
lib/models/StudipStudyArea.class.php
with
70 additions
and
25 deletions
lib/classes/StudipTreeNodeCachableTrait.php
0 → 100644
+
59
−
0
View file @
2bbcfb7b
<?php
trait
StudipTreeNodeCachableTrait
{
protected
static
$descendants_cache_array
=
null
;
protected
static
function
getDescendantsCacheArray
():
StudipCachedArray
{
if
(
self
::
$descendants_cache_array
===
null
)
{
self
::
$descendants_cache_array
=
new
StudipCachedArray
(
static
::
class
.
'/descendants'
,
30
*
60
);
}
return
self
::
$descendants_cache_array
;
}
protected
static
function
registerCachableCallbacks
(
array
$config
):
array
{
if
(
!
isset
(
$config
[
'registered_callbacks'
]))
{
$config
[
'registered_callbacks'
]
=
[];
}
if
(
!
isset
(
$config
[
'registered_callbacks'
][
'before_store'
]))
{
$config
[
'registered_callbacks'
][
'before_store'
]
=
[];
}
$config
[
'registered_callbacks'
][
'before_store'
][]
=
function
(
$node
):
void
{
self
::
getDescendantsCacheArray
()
->
expire
();
};
if
(
!
isset
(
$config
[
'registered_callbacks'
][
'after_delete'
]))
{
$config
[
'registered_callbacks'
][
'after_delete'
]
=
[];
}
$config
[
'registered_callbacks'
][
'after_delete'
][]
=
function
(
$node
):
void
{
self
::
getDescendantsCacheArray
()
->
expire
();
};
return
$config
;
}
protected
function
getDescendantIds
():
array
{
$cache
=
self
::
getDescendantsCacheArray
();
if
(
isset
(
$cache
[
$this
->
id
]))
{
return
$cache
[
$this
->
id
];
}
$ids
=
[];
foreach
(
$this
->
getChildNodes
()
as
$child
)
{
$ids
=
array_merge
(
$ids
,
[
$child
->
id
],
$child
->
getDescendantIds
());
}
$cache
[
$this
->
id
]
=
$ids
;
return
$ids
;
}
}
This diff is collapsed.
Click to expand it.
lib/models/RangeTreeNode.php
+
5
−
13
View file @
2bbcfb7b
...
@@ -27,6 +27,8 @@
...
@@ -27,6 +27,8 @@
*/
*/
class
RangeTreeNode
extends
SimpleORMap
implements
StudipTreeNode
class
RangeTreeNode
extends
SimpleORMap
implements
StudipTreeNode
{
{
use
StudipTreeNodeCachableTrait
;
protected
static
function
configure
(
$config
=
[])
protected
static
function
configure
(
$config
=
[])
{
{
$config
[
'db_table'
]
=
'range_tree'
;
$config
[
'db_table'
]
=
'range_tree'
;
...
@@ -41,12 +43,13 @@ class RangeTreeNode extends SimpleORMap implements StudipTreeNode
...
@@ -41,12 +43,13 @@ class RangeTreeNode extends SimpleORMap implements StudipTreeNode
];
];
$config
[
'has_many'
][
'children'
]
=
[
$config
[
'has_many'
][
'children'
]
=
[
'class_name'
=>
RangeTreeNode
::
class
,
'class_name'
=>
RangeTreeNode
::
class
,
'foreign_key'
=>
'item_id'
,
'assoc_foreign_key'
=>
'parent_id'
,
'assoc_foreign_key'
=>
'parent_id'
,
'order_by'
=>
'ORDER BY priority, name'
,
'order_by'
=>
'ORDER BY priority, name'
,
'on_delete'
=>
'delete'
'on_delete'
=>
'delete'
,
];
];
$config
=
self
::
registerCachableCallbacks
(
$config
);
parent
::
configure
(
$config
);
parent
::
configure
(
$config
);
}
}
...
@@ -240,17 +243,6 @@ class RangeTreeNode extends SimpleORMap implements StudipTreeNode
...
@@ -240,17 +243,6 @@ class RangeTreeNode extends SimpleORMap implements StudipTreeNode
return
DBManager
::
get
()
->
fetchAll
(
$query
,
$parameters
,
'Course::buildExisting'
);
return
DBManager
::
get
()
->
fetchAll
(
$query
,
$parameters
,
'Course::buildExisting'
);
}
}
public
function
getDescendantIds
()
{
$ids
=
[];
foreach
(
$this
->
children
as
$child
)
{
$ids
=
array_merge
(
$ids
,
[
$child
->
id
],
$child
->
getDescendantIds
());
}
return
$ids
;
}
public
function
getAncestors
():
array
public
function
getAncestors
():
array
{
{
$path
=
[
$path
=
[
...
...
This diff is collapsed.
Click to expand it.
lib/models/StudipStudyArea.class.php
+
6
−
12
View file @
2bbcfb7b
...
@@ -30,6 +30,8 @@
...
@@ -30,6 +30,8 @@
class
StudipStudyArea
extends
SimpleORMap
implements
StudipTreeNode
class
StudipStudyArea
extends
SimpleORMap
implements
StudipTreeNode
{
{
use
StudipTreeNodeCachableTrait
;
/**
/**
* This constant represents the key of the root area.
* This constant represents the key of the root area.
*/
*/
...
@@ -53,6 +55,9 @@ class StudipStudyArea extends SimpleORMap implements StudipTreeNode
...
@@ -53,6 +55,9 @@ class StudipStudyArea extends SimpleORMap implements StudipTreeNode
'class_name'
=>
StudipStudyArea
::
class
,
'class_name'
=>
StudipStudyArea
::
class
,
'foreign_key'
=>
'parent_id'
,
'foreign_key'
=>
'parent_id'
,
];
];
$config
=
self
::
registerCachableCallbacks
(
$config
);
parent
::
configure
(
$config
);
parent
::
configure
(
$config
);
}
}
...
@@ -64,7 +69,7 @@ class StudipStudyArea extends SimpleORMap implements StudipTreeNode
...
@@ -64,7 +69,7 @@ class StudipStudyArea extends SimpleORMap implements StudipTreeNode
/**
/**
* Returns the children of the study area with the specified ID.
* Returns the children of the study area with the specified ID.
*/
*/
static
function
findByParent
(
$parent_id
)
public
static
function
findByParent
(
$parent_id
)
{
{
return
self
::
findByparent_id
(
$parent_id
,
"ORDER BY priority,name"
);
return
self
::
findByparent_id
(
$parent_id
,
"ORDER BY priority,name"
);
}
}
...
@@ -601,17 +606,6 @@ class StudipStudyArea extends SimpleORMap implements StudipTreeNode
...
@@ -601,17 +606,6 @@ class StudipStudyArea extends SimpleORMap implements StudipTreeNode
return
$path
;
return
$path
;
}
}
private
function
getDescendantIds
()
{
$ids
=
[];
foreach
(
$this
->
_children
as
$child
)
{
$ids
=
array_merge
(
$ids
,
[
$child
->
id
],
$child
->
getDescendantIds
());
}
return
$ids
;
}
/**
/**
* Constructs an index from the level hierarchy, This index is a number,
* Constructs an index from the level hierarchy, This index is a number,
* containing the "depth" level and the priority on this level. For example,
* containing the "depth" level and the priority on this level. For example,
...
...
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