New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enh: Introduce FindInstanceInterface
- Part 2: Implementing throughout the code
#6463
base: statable
Are you sure you want to change the base?
Conversation
If you're referring to User::findIdentity(), than yes, that's kind of what I meant. And it is not typed at all, neither with the input, not the output. I would personally allow
humhub/protected/humhub/modules/user/models/Group.php Lines 355 to 356 in 9a28225
humhub/protected/humhub/modules/user/models/Group.php Lines 385 to 386 in 9a28225
humhub/protected/humhub/modules/user/models/UserFilter.php Lines 31 to 35 in 9a28225
And there are potentially many more if considering modules. Having those functions, for the Membership class we only require one as the rest is taken care of in the User and Space classes. What is the advantage of having a strongly typed input, if the type is verified in the function and throws an exception, as invoking the function with a wrong type would?
|
The alternative to add those methods to However, performance-wise it's probably better to have them in the User/Space classes, as the methods are very likely to be called and those classes already loaded. Loading another or two other classes would create more overhead. The User::findIdentity() method is part of the I did not want to use We could opt for a more generic pattern, as in:
In case of a multi-row-pk (as with Having this generic approach, this would also allow to use an interface to define the methods. Otherwise we could use
Any other suggestion, @luke- ? |
Actually, I've just set no return type on the |
find*
methods to get (cached) instances of User
s and Space
sFindInstanceInterface
with methods to get (cached) instances of e.g. User
s, Space
s, and Membership
s
Note for reviewers: This PR is now building upon and including PR #6457. Hence code review would be easier if either 6457 is already merged into develop, or both are applied to a separate branch. |
0bd717b
to
202d311
Compare
0f72796
to
79bc572
Compare
9fb9185
to
9d984e4
Compare
FindInstanceInterface
with methods to get (cached) instances of e.g. User
s, Space
s, and Membership
sFindInstanceInterface
with methods to get (cached) instances - Part 2
@luke- as laid out in the introduction to part 1 of this PR:
I know it is a significant change and not something you like to add to v1.15. However, I do feel that the big change is really the introduction of the runtime cache and this might help mitigating undesired side-effects. However, it could also be ready for a hotfix in v15.1 if the runtime cache proofs to be tricky. |
@luke- From #6512 (comment):
Yes, I appreciate that. I mean the cached relation can probably be undone. However, for me arises the question: why not using the default db-caching mechanism from Yii2 and just deal with it's clearing as we do in the runtimeCache? Unless you would opt for the New RuntimeCache engine #6482 that brings the advantage to store the records under different cache keys, e.g to be looked up both bi |
…ntActiveRecord class
9d984e4
to
f41ba7d
Compare
f41ba7d
to
6af25cf
Compare
…dInstance()` call, rather than `$model::FindOne()`
6af25cf
to
8b693a5
Compare
@martin-rueegg Just some thoughts to perhaps simplify it further:
|
FindInstanceInterface
with methods to get (cached) instances - Part 2FindInstanceInterface
- Part 2: Implementing throughout the code
@luke- Thanks for your your input!
Good idea. Done. Is there anything against to integrate the following files directly into
|
Missed that. There is no reason that it is not derived from our standard
I would prefer the code base of The RTC is a standard Yii array cache including most features + good documentation. What specific management features are you missing?
Hmm, I actually see As before, most (module-) devs should still work with standard Yii 2 AR & ActiveQuery methods.
|
Thanks, I've seen that. However, as mentioned repeatedly and at different places :-) I consider the current implementation and usage of RTC not fit for production. Why? Simply because there are failing tests as soon as you enable RTC during tests. Why this should be not a problem of the testing environment is also explained at various locations, including I have at those locations argued, that
As such, it is the question, if the change you made to
I guess the main question boils down to wheter the RTC should be exclusivly be used for record caching (i.e. So for example, with the current implementation in Putting all this functionality into So, we want to have the RTC available for The functionality that is currently in
The "parts of Relying on the code of
I disagree on this one. IMO, it must be in the interest of the software provider, that the software is running as performant as possible. So it should not depend on the knowledge of a module developer whether or not looking up a user is performant. I would say, it usually depends more on the record type, rather than on the developer writhing the code. For example, looking up a User should by default be cached, particularly on single lookup (we do now cache every record of From that perspective, I wonder if it would not be better to abandon the special method humhub\components\ActiveRecord::findOne($condition, $cached = false): ?self;
humhub\components\CachedActiveRecord::findOne($condition, $cached = true): ?self {
return parent::findOne($condition, $cached);
} This would allow us to make some sane defaults (as caching I guess, using this method would be a much more elegant solution!
/**
* Returns a single active record model instance by a primary key or an array of column values.
*
* The method accepts:
*
* - a scalar value (integer or string): query by a single primary key value and return the
* corresponding record (or `null` if not found).
* - a non-associative array: query by a list of primary key values and return the
* first record (or `null` if not found).
* - an associative array of name-value pairs: query by a set of attribute values and return a single record
* matching all of them (or `null` if not found). Note that `['id' => 1, 2]` is treated as a non-associative array.
* Column names are limited to current records table columns for SQL DBMS, or filtered otherwise to be limited to simple filter conditions.
* - a yii\db\Expression: The expression will be used directly. (@since 2.0.37)
*
* That this method will automatically call the `one()` method and return an [[ActiveRecordInterface|ActiveRecord]]
* instance.
*
* > Note: As this is a short-hand method only, using more complex conditions, like ['!=', 'id', 1] will not work.
* > If you need to specify more complex conditions, use [[find()]] in combination with [[ActiveQuery::where()|where()]] instead.
*
* (...)
*
* @param mixed $condition primary key value or a set of column values
* @return static|null ActiveRecord instance matching the condition, or `null` if nothing matches.
*/
public static function findOne($condition); |
Introduce FindInstanceInterface
Part 2: Implementing throughout the code
FindInstanceInterface series:
FindInstanceInterface
- Part 1.a: Creating base classes #6503FindInstanceInterface
- Part 1.b: TagDependency #6528FindInstanceInterface
- Part 2: Implementing throughout the code #6463PR Admin
What kind of change does this PR introduce?**
Does this PR introduce a breaking change?
The PR fulfills these requirements:
develop
branchOther information:
#6457 (comment) and following