Problem/Motivation
The History service uses procedural functions with logic that is difficult for contrib to modify, and only supports the node entity type.
Prior to post #221 these problems were being fixed in this issue. As this scope was too large to effectively manage in a single issue, it is now split.
Remaining tasks
#3267010: Introduce a generic HistoryRepository service without changing storage or caching
#3267011: [PP1] Use the HistoryRepository in the comment & node modules
#3267021: Deprecate history procedural functions
#3267014: Block & migrate tests fail to declare dependency on history
#3267015: Make History storage support any entity type
#3274480: Make history repository optionally support "edit" besides "view"
#3267016: Support history in views for entity types other than node
#3267019: Make history's frontend code support non-node entity types
#3267020: Use caching for history
| Comment | File | Size | Author |
|---|
Issue fork drupal-2081585
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
andypostInitial implementation on top of #1029708-60: History table for any entity
The method names are need discussion and tests
Comment #3
dawehnerAny reason to not inject that service?
Comment #4
andypostRemoved changes to history_read() and write() and mark them deprecated.
Renamed service name to 'history.manager' and should fix most of comment related tests.
No idea how to fix upgrade tests, forum manager depends on new history module...
@dawehner The reason is that scope of current_user service is limited by request scope and using
strict=falseis ugly hereComment #5
andypostShould fix upgrade tests
Comment #6
dawehnerIf we can't be sure that the history manager is available we should check that the variable exists before we call it?
Comment #7
andypostMakes sense
Comment #8
dawehnerWhat about marking the HistoryManagerInterface on the constructor = NULL?
Comment #9
andypostYep, this will document that the dependency is optional
Comment #10
andypostfix exceptions, enough for today!
Comment #12
larowlanTest results for posterity:
Comment #13
larowlan#10: drupal8.history-module.2081585-10.patch queued for re-testing.
Comment #15
andypostRe-roll and fixes
Comment #17
larowlanentity_id => entity
that was read
The ID of the entity that was read.
\Drupal
Given uid is an optional parameter, shouldn't that be in the mix here or we'll need a resetCache method.
ID
Attached patch fixes these and tests.
Comment #19
larowlan#17: history-manager-2081585.17.patch queued for re-testing.
Comment #20
dawehnerAccording to HistoryManager::read() this returns history information by entity ID, though on the left side this sets the history information to a specific value.
Comment #21
damiankloip commentedGenerally looking pretty good!
Nitpick alert: 'The history manager service' ?
Can this constant get converted to a class constant?
What's going down here? why the casting? If it's legit, maybe a comment..
We could return an assoc array of the results so they are in the form entity_id => timestamp already. But I guess you want this casting.
Could just inject the current user service instead.
This should just call resetCache() instead.
And here.
We could let resetCache() take an optional array of entity ids to clear? Just a thought.
Resets
Also, do you think the new HistoryManager class needs it's own unit test?
Comment #22
andypostThis issue is mostly ready to replace #1029708-54: History table for any entity so once all nitpicks addressed probably one of them should be closed as duplicate. I've started this one to figure out how the service should operate and then move to #1029708-61: History table for any entity
Having
current_userinjected breaks a lot of tests that changes users so better have optional argumentMakes no sense, because we should pass their entity types as well.
Makes sense
Comment #23
damiankloip commentedI'm not sure how just changing this for the injected current_user service will stop using $account etc..? You will still have the same logic as now.
Comment #24
andypostThe reason is #2102027: Add back the request scope to the current user service so service should be agnostic to
current_userthat could be limited to request scopeSeems we need to add $account to read() and check the usage
Comment #25
andypostre-roll with fixes for #21
Comment #27
sunThe name "HistoryManager" wasn't very intuitive and self-descriptive until I looked at what it actually does.
I do not have a concrete improvement suggestion, but I wonder whether we're able to find a more intuitive name?
The goal for a better name would be to at least hint a little bit at what exactly this service is doing (retrieving and updating last viewed timestamps for entities).
I know that we struggled a lot with finding a proper name for History module in the past already (and IIRC, we still have a dedicated issue open for that even), but perhaps:
\Drupal\history\EntityViewManager
?
Hm. The "read" and "write" terminology originates from the procedural implementation, in which it was rather unusual to use more descriptive function names.
In an object-oriented implementation, developers expect more self-explanatory method names.
Could we rename these methods along the lines of the following?
getLastViewedTimestamps()
updateLastViewedTimestamps()
For brevity, I guess it would be fine to exclude the "Timestamp" part and just go with getLastViewed() and updateLastViewed().
Such method names would be much more clear compared to read() and write(), wouldn't they?
Lastly, while I understand the use-case-driven difference of getting multiple last viewed timestamps vs. updating a single last viewed timestamp, I do not understand why only the update method allows to pass a custom user account — if there's a use-case for updating the history for a user account that is not the current user, then there must also be a use-case for getting the history for a user that is not the current user, no?
Finally, as this is all about entity system entities (as opposed to arbitrary "entity type" strings), would it make sense to replace the $entity_type + $entity_id arguments in the update method with a single EntityInterface $entity argument?
updateLastViewed(EntityInterface $entity, AccountInterface $account = NULL)
I consider these aspects to be the most important part of this patch, as we're defining an interface (API) for a service that may be replaced with a different implementation.
I don't know whether it is technically feasible (primarily concerning performance), but would it be possible to replace the $uid argument with AccountInterface $account?
Otherwise, we would be hard-coding an assumption that $account->uid is the ID of user accounts in this API and all consuming code — whereas AccountInterface properly defines what exactly a user is in Drupal, regardless of the actual implementation.
As above, is it possible to replace the two arguments with EntityInterface $entity?
Otherwise, deleteByEntity() claims to talk about entities, but an actual entity is not part of the API contract?
Unless I'm terribly mistaken, I think you meant 'initial' instead of 'default', no?
'default' specifies the (permanent) default value for the column, whereas 'initial' specifies the initial value of all existing rows for a newly created column.
In D8, didn't we globally limit the maximum length of entity_type to ~64 characters already?
These tables can quickly grow very large.
For (MySQL) query statement performance optimization, columns that share and have the most repetitive values should always be specified first in the primary key and all other indexes.
For the history tables, I guess it would be reasonable to expect that values will increasingly vary in this order:
1) entity_type
2) uid
3) entity_id
Why is the history cache manually reset here?
Since the test uses the internal browser to request pages and logs in another user between assertions, the history functionality should work as-is.
The manual cache reset in the test runner appears to hide a potentially existing bug?
Comment #28
andypostShould fix failure, also trying to address #27.8
@sun thanx a lot for the review, I'm not so good in naming so should think a bit more about 1 and 2,
3) makes sense
4) yep, and convert to
ContentEntityInterface5) not found any references about "initial" but the purpose exactly the same, so added hunk to remove this and @todo about migrate
6) not found any issues about, it there any please point me, it makes sense to file separate issue for that (comment field affected too)
7) probably, no idea how to test this
EDIT suppose defaults for entity_type and entity_id should be removed like #1029708-69: History table for any entity (70)
PS: related about 1 #1961548: [Policy, no patch] Decide how the module-specific services are made available as static methods (similar to \Drupal::$service())
Comment #29
sunWow, that was quick! :)
4) I do not really see a reason for why history/last-viewed tracking should be limited to content entities? Is there any? Oh, the integer entity ID vs. string entity ID, I guess? Bummer.
That said, is that storage related detail something we want to hard-code in the API/Interface? What if I'm replacing the entire entity history storage with a key/value store, which in turn would enable me to track views of e.g. config entities, too? :)
As a consequence, not sure whether PHP allows for that, but could the interface take a EntityInterface, but the default (SQL) implementation of History module would take a ContentEntityInterface?
5) Indeed, the 'initial' key is poorly documented, but it does exist:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Schema.p...
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Driver!m...
In short, you can simply specify this:
Comment #30
andypostFixed 3,4,5 and remaining @todo in comment module
Comment #31
andypostThis names better explains and could be grep'ed easily
Comment #34
sunGreat! :)
The code was using the _read_multiple() function before; the return value is an array and not the timestamp value of the requested entity ID, so that obviously breaks :)
If you can just move the 'entity_type' field in these indexes to come first, then I'm happy and promise to shut up :)
(identical change in the update function)
Do we actually have to keep those deprecated procedural functions around? It looks like the only core consumer is being converted as part of this patch already?
If possible, let's remove those procedural wrappers directly with this patch?
The last remaining API tweak would be to change the signature to updateLastViewed(EntityInterface $entity), too, if possible. :)
Comment #35
andypost@sun Thanx a lot for point!
1) fixed
2) changed as proposed
3) No api change to make this in, and related #2042165: Add a 'deprecated' module that includes deprecated functions only when enabled
4) makes sense, fixed
Comment #37
sunStill an array :)
I guess it would make sense to move this constant into the HistoryManagerInterface?
As this column is part of the primary key, we have to specify a default value of
'default' => ''in the update function.Also note that the schema still defines "node" as default value.
Comment #39
andypost1) fixed
2) this is not constant
define('HISTORY_READ_LIMIT', REQUEST_TIME - 30 * 24 * 60 * 60);suppose we need separate issue to deal with it3) fixed, set to empty as 'node' makes no sense as default
Comment #40
andypostFixes broken tests
Comment #42
andypost40: history-manager-2081585.40.patch queued for re-testing.
Comment #44
andypostre-roll
Comment #45
andypostCan someone RTBC this?
Comment #46
dawehnerI wonder whether we can find a better description of the capabilities of a history manager, as your current one does not provide any information. "Provides the last view on entities", (maybe?)
Comment #47
joelpittetShould this @todo be finished up before RTBC?
How is this being treated now, as I don't see that 30 day equation in the new service?
Comment #48
andypost#46 fixed
#47.1 fixed
#47.2 HISTORY_READ_LIMIT is the same constant
HISTORY_READ_LIMIT
Comment #49
dawehnerYeah "manage" does not really tell you a lot.
/**
* Defines an interface to store and retrieve last view timestamp information of entities.
*/
interface HistoryRepositoryInterface {}
Comment #50
amateescu commentedSince we're updating this, we can also put a type hint for $timestamp.
Should we also explain in which case this service might not available?
There is no {entities} table..
Comment #51
andypost@dawehner thatx for idea, just fixed to 80 chars limit
Comment #52
andypostLet's see if upgrade tests still affected...
Comment #53
dawehnerOh, I automatically assumed that we wanna rename the class and all variables as well. Don't you think otherwise it would be confusing?
Comment #55
andypostSuppose this service needs current user injected otherwise the static cache is invalid
OTOH the history module storage assumes that it should be user to track the last authorized
$account should be injected or passed as required argument
Comment #56
andypostTo track anonymous node views there's statistics module so "history" should track authorized
Comment #57
andypostRe-roll and clean-up:
- user account is required
- s/manager/repository
- fix forum manager test
Comment #59
andypostFix tests
Comment #60
andypostTo keep static cache valid the current user should be injected
Comment #61
dawehnerI think we should make it at least possible to pass in a user/UID to get the information from a different user.
Comment #62
andypostAccount added as required argument, now we should get rid the static cache and purge functions
Comment #64
andypostfixed remains of "manager"
Comment #66
andypostone more round of bugfixes caused by rename
Comment #67
larowlanThis looks ok, but leaving for @dawehner to have one last look
Comment #68
dawehnerThank you for the fixes!
Comment #69
andypostAdded change notice https://drupal.org/node/2197189
Adjusted title and summary
Also re-roll after #2184231: Use ConfigFactoryInterface to type hint ConfigFactory
TO EDIThttps://drupal.org/node/1845806Comment #70
andypost1) Removed
current_userservice dependency according #2180109-96: Change the current_user service to a proxy2) fixed static cache to cache per user.
3) extended service from
DependencySerializationto prevent serialization of static cache and database connection4) filed follow-up for forum manager service #2201659: Fix serialization of the forum manager and dependency on current_user service
Comment #71
andypostThere's issue with
entity_idnow according to #2195915-7: Cannot save text filter config using PostgreSQL if Comment is enabled [blocks installation!]So this kind of storage is fragile, trying to re-think this into field...
otoh this out-of-bound data that does not coupled to entity, that means update of history does not lead to update of entity
Comment #72
larowlanBack to RTBC
Comment #73
andypostAbout consistency for
entity_id(could be integer or string) suppose we have follow-up #2100203: Make config entities use dots in machine names consistentlySuppose this issue ready, @catch I think for the storage we can at least in 8.0.1 add second table field
{bundle_id}with logicreturn history->id() ?: history->bundle_idComment #74
alexpott2081585-history-service-70.patch no longer applies.
Comment #75
andypostRe-roll after #2151459: Enable node render caching
Comment #76
alexpott2081585-history-service-75.patch no longer applies.
Comment #77
andypostRe-roll after #2194897: Rename Database\Query\Merge::key() to keys(), retain a BC alias for key()
Comment #78
sutharsan commentedComment #79
catchThis could use an EXPLAIN for the new query, iirc it's pretty bad as it is and this may make it worse.
Similar to the entity caching issue, we probably want to move to table-per-entity type. This is one of the most frequently written to, read from tables and can have tens of thousands of rows if not more.
Why not just $vars['history'] = array() - then we wouldn't need the __wakeup()?
Comment #80
andypostIt's nice idea about "table-per-entity type" but there's no core api to generate this tables.
Suppose we need to create/drop this tables manually when entity types is defined or make history a configurable field to inherit storage
The same applies to comment table
Comment #81
mgifford#1029708: History table for any entity was marked a duplicate of this issue. But it's also in the todo here in Core in comment.module:
Comment #82
joelpittetComment #83
Crell commentedComment #84
Crell commentedComment #85
cilefen commentedI removed the "beta target" tag because this is pushed to 8.1.x.
Comment #87
andypostservice should be swappable like related issue
Comment #88
jonathanshawThis patch stalled 2 years ago on @catch's point:
Is there a reason to block this patch on this point? Would it be better to proceed with this patch and leave table-per-entity for a different issue (by reopening #1029708: History table for any entity as no longer a duplicate)? Does this patch make the lack of table-per-entity worse than it currently is without this patch?
Comment #89
andypostthere's proper tag
Comment #92
nevergoneAnd now?
Comment #95
dillix commentedIs there any news with HistoryManager?
Comment #96
nevergoneI tried again re-roll the patch #77, but not success. Can anyone help me?
Comment #98
claudiu.cristeaAs this helps #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset() by removing
drupal_static(), I'm adding that as a parent issue.Comment #99
jhedstromComment #101
moshe weitzman commentedAnyone using this patch in Production? I'm curious how its working for you. Our use case is relatively low volume.
Comment #102
andypost@moshe weitzman I used it long ago but then we removed history module at all(
Comment #103
vladbo commentedRe-roll for 8.8.x
Comment #104
vladbo commentedFixed tests and ForumManager constructor.
Comment #105
vladbo commentedFixed dependencies for some tests
Comment #106
vladbo commentedComment #107
vladbo commentedAdded update for scheme which also fixes failed tests.
Comment #108
andypostwould be great to start numbering with 8801() because of current version
Comment #109
daffie commentedMy first quick review:
This cannot be removed. It must deprecated.
There are a lot of instances where "array()" is used. Please change it to "[]".
I think that this part can be removed.
Should this service not be backend overridable?
I do not think that these changes are necessary.
Comment #110
vacho commentedI update the patch #107 solving observations at #108
About observations at #109
Comment #111
daffie commentedFor #109.1: Because Drupal core does not use this variable any more does mean that there are contrib or other modules that depend on the variable to be there.
For #109.3: The part can be removed, because right after we test if that variable is empty. If it is empty then we are going to set the variable. After that the value of the variable is returned. The part that you want to add does not help in any way. it only makes the code more complicated. Please remove this change.
For #109.4: The whole idea of this issue is to back history modules database queries swappable. For that to be possible the service needs to be backend overridable. See: https://www.drupal.org/node/2306083.
For #109.5: The value for $this->currentUser() is always set. It can be for an authenticated user or for an anonymous user. Please remove this change.
Comment #112
vladbo commentedFor #109.1: I've added back
define('COMMENT_NEW_LIMIT', REQUEST_TIME - 30 * 24 * 60 * 60);But it's not used in any contrib module.
For #109.3: Fixed.
For #109.4: Fixed.
For #109.5: Fixed.
Also, I've set default value for entity_type column in history table as 'node'.
Comment #113
vladbo commented- Removed rejected changes after applying patch;
- Fixed hook_update_N id as it was said in #108;
- Some minor fixes;
Comment #114
vladbo commentedUpdated
lazyBuildercallback.Comment #115
daffie commentedMy second review:
Can we change the variable name to $timestamps. To make clear that it is an array of timestamps and not a single timestamp.
Just to be sure. If you remove this change the test will fail? Also, I am unable to find the function comment_num_new().
Can we rename the variable $return to something more descriptive like $entities. If you have a better idea that would be great.
Maybe better: "Deletes the history for the given user account."
Comment #116
andypost#115.2 update hook must never use schema which may change over time and could gone to service with ensureTable like few other core services doing
Comment #117
vladbo commented1. Fixed.
4. Removed as it doesn't affect on test.
5. Fixed.
6. Fixed.
Comment #118
jonathanshawSo all review points adressed except #115.3:
and #79.1 and #79.3
Comment #119
daffie commentedI would like to state that I agree with @andypost’s point from comment #116.
The patch looks good to me. What I still mis is a specific update test for the function history_update_8801().
There is documentation for how to write such a test. See: https://www.drupal.org/docs/8/api/update-api/writing-automated-update-te....
Comment #120
vladbo commentedAdded test for
function history_update_8801()and fixed failed tests.Comment #121
vladbo commentedGreen now.
Regarding #79:
#79.1 - I don't get what should be changed.
#79.3 - The same thing is used in
ForumManager.phpandTermStorage.php. Do we really need to change it?Comment #122
daffie commentedThank you @Vlad Bo for adding the update test.
The issue summary is updated.
The patch is now RTBC for me.
The architectural review needs to be done by a core committer.
Comment #123
catchI don't think 'node' should be the default in the actual schema definition if we're trying to make the module entity-type agnostic.
nit: ID.
Does this need to be in the interface?
Also the protected property here would be a good case for #3047289: Standardize how we implement in-memory caches. We're already using this for some other services.
Comment #124
volegerSeems you would not define the default field value so you will fill the value of entity_type field once after the field updates. I suggest moving that insert operation in the separate hook_update_N implementation.
Comment #125
vladbo commented#123.1 - fixed.
#123.2 - removed.
Default value for entity_type field was removed and update query was added to set it.
Comment #126
vladbo commentedComment #127
daffie commentedI am missing in the update test that the value of the column entity_type is equal to "node".
edit: @Vlad Bo: The changes that you made look good to me.
Comment #128
vladbo commentedAdded check for entity_type value in update test.
Comment #129
daffie commentedAll the points from @catch are fixed. Back to RTBC.
The architectural review needs to be done by a core committer.
Comment #130
catchThis is no-longer in the interface but it still has @inheritdoc. I think we should use a memory cache implementation straight off here, which would also allow us to remove this as well as the the __sleep() and __wakeup() methods.
Comment #131
vladbo commentedRemoved resetCache method and added memory cache implementation.
Comment #133
vladbo commentedFixed loading timestamp from cache
Comment #134
vladbo commentedOne more fix for tests
Comment #135
vladbo commentedComment #136
daffie commentedEverything that @catch asked for has been added to the patch.
I have 2 minor issues left for the patch:
Minor: This needs to be on two lines.
I do not think that this patch will land in 8.8.
Thanks @Vlad Bo for your work on this patch.
Comment #137
andypostIt looks mostly ready, just not sure it fits into 8.8 or 8.9 but that's framework manager review
It needs pointed to what use instead and change record link
Builder should inject history repository service
Nice clean-up but it adds one more optional dependency to comment manager and I'm ok to resurect #2188287: Split CommentManager in two
could use HistoryRepositoryInterface::class
new format is bit different - could be fixed on reroll
HistoryRepository::class
it looks like this methods could throw exceptions so needs to document
Comment #138
vladbo commentedComment #139
vladbo commentedMostly fixed:
Comment #140
longwaveComment #142
vladbo commentedFixed fails, changed format of trigger_error messages and added dependency in comment module.
Comment #144
ridhimaabrol24 commentedRerolling patch for 9.1.x and trying to fix test cases.
Comment #146
ridhimaabrol24 commentedFixing test cases!
Comment #148
volegerKeeping fix the tests.
Fixed the fixture location definition in the update test.
Added missing schema installation calls in failing tests.
Comment #150
nevergonePatch re-rolled and manual fixed.
Comment #151
nevergoneComment #153
nevergoneFix test dependencies and code style.
Comment #155
nevergonefix CommentLinkBuilderTest()
Comment #156
nevergoneEverGreen!
Please test, review and feedback!
Comment #157
nevergonePlease test and review, thanks!
Comment #158
volegerThe versions needs to be updated.
Comment #159
nevergoneFix deprecation comment.
Comment #160
voleger+1 for RTBC
Comment #161
andypostI think it's not yet ready, because usage of "current user" and history module enabled needs more clean-up
Most of places accessing history only when module enabled and current user is authenticated, that's why I removed account as argument from repository.
I think it needs special api method to return access for current user to api, but maybe it could be done in follow-up
Also the split of arguments for entity type and IDs are confusing - we can't apply type-hint to entity ID[s] as they could be strings or integers
The patch starts it, also using local variables to minimize entity api calls in implementation
there's no runtime hook to override last viewed, needs to mention in CR
Not sure account itself should be passed as only $user_id used
update using ID and authenticated but can skip
Comment #162
andypostmissed to return value
Comment #164
paulocsFixing code standard.
Please, not consider the files attached here. See comment #165.
Comment #165
paulocsOps, patch and interdiff on comment #164 are wrong.
I'm attaching the right files.
Comment #166
paulocsComment #169
nevergoneGreen, please review!
Comment #170
longwaveShould comment really depend on history? Can we make this optional, as it was before?
Comment #171
nevergoneComment #173
nevergonehistory.repository is a optional service.
Comment #174
andypost@nevergone looks great! just needs to deal with deprecation and few nitpicks
Needs fix for CS
it needs clean-up cos constructor no longer changing
it should use setter instead of that, moreover as it passed - the test works wrong!
I think $this->any() must be replaced with $this->atLeastOnce()
the same here - use setter instead of constructor
any reason for not-null when default is empty string?
maybe it should be 9101?
needs to fix CS (empty line before @see)
Also as deprecation policy states to trigger and add deprecation test https://www.drupal.org/about/core/policies/core-change-policies/drupal-c...
Moreover would be great to file follow-up issue against D10 to remove it
same here
Comment #175
nevergoneComment #176
nevergoneFix database schema
Comment #177
andypostGreat to see this changes, will check at morning
Comment #179
nevergoneComment #180
longwaveThe changes look pretty good to me, a couple of things I spotted:
This needs a deprecation test.
This also needs a deprecation test.
This needs @trigger_error and a deprecation test. Also should we be changing the signature here?
Comment #181
andypostNeeds re-roll for https://www.drupal.org/node/3176667
Comment #182
nevergonePlease little help me because history_read() and history_read_multiple() are not tested currently. Thanks!
Comment #183
andypostHere's legacy test and few nitpicks
Comment #184
andypostthe order of execution reverted to original - no reason to do fiunction call if history missing
I did revert it because
- out of scope
- formal API change
remaining legacy usage
Comment #185
nevergoneOh, thanks! I also learned something today! :)
Comment #186
longwaveThanks, this looks ready to go now.
Comment #187
alexpottI'm really not sure that having to add the history module to all these tests is a viable approach. Why is this necessary?
What is this here for? Pointing to the issue that adds this is not useful.
We should have a string typehint and a return type hint here.
Need return typehints.
Comment #188
alexpottWhy are we using setter injection over constructor injection?
This needs documenting in the CR. Also this functionality we pretty undocumented and does not look to be used by contrib. But a custom implementation on a site will break after this change.
I've reverted this change and the test still passes. I guess the change to add this to all tests was done prior to adding a way to only add the history repository if it exists.
This comment is now incorrect. So I guess we need a follow-up to expand what the new comments thing is attached to. Also this has a implicit dependency on the history module that's not managed very well.
Comment #189
alexpottThe forum module depends on history. This service should definitely be injected into the constructor and do the deprecation dance because it is mandatory.
The changes here are a performance regression. Prior to the change it was only doing a read when it hadn't before.
Comment #190
longwaveRe #188.1 we need setter injection here because history is not a dependency of comment and might not be enabled, iirc you can't do constructor injection with optional services in Symfony?
Comment #191
andypostWorking on to get rid of setter, optional services should work https://symfony.com/doc/current/service_container/optional_dependencies....
on #189.2 - repository should care about caching (guess memory cache) but that could use follow-up
Meantime I'm not sure the change fits into beta target, as it adds new API and deprecates
So I think about removal of hook_schema here at all for implementation of storage based on core's
keyvalue.expirableHaving separate collection per entity type looks less API surface and easy to scale using redis/keydb existing modules
It was suggested initially #17
Comment #192
andypostPatch should address type hints and service injection
I think only
\Drupal\comment\Plugin\views\field\NodeNewComments::preRender()makes query using history table without check that history enabled, and that's why all this fixes in tests appearedTests classes (40kb interdiff) is comment #146
PS: I set
HistoryRepositoryInterfaceas return type forupdateLastViewed()becauseselfworks only since PHP 7.4Comment #193
alexpott@andypost I removed it from one test and it still passed. This change should not make the history module necessary for all these tests. That part of the patch needs to be reverted and fixed.
Re #190 ah I see. I wonder if we should try to invert or decouple the dependency stuff.
COMMENT_NEW_LIMIT is no longer used.
This couples comment to the history module. Did we consider dispatching an event instead of setting a history service.
Comment #194
andypostOnly forum require history dependency (maybe we should replace setter with optional argument)
Patch does clean-up of history dependencies in tests
Comment #195
alexpottForum depends on history - I don't see why we need setter inject here. This can be a normal constructor argument.
Comment #197
longwaveOh I thought from reading https://symfony.com/doc/current/service_container/optional_dependencies.... that this didn't work in YAML:
but now I see
I think this means that if we need to inject another new service here in the future, it will be more tricky, but I guess we can deal with that if/when it happens.
Comment #198
andypostI applied for issue forks and meantime fix for failed tests
Leaving NW as it needs deprecation fix for forum manager
Also wanna explore tempstore way in issue fork
Comment #202
nevergone9.2.x??? :((((
Comment #203
nevergoneIs there a realistic chance of you getting to the 9.1.0?
Comment #204
nevergoneRe-rolled patch from #2081585-198: [META] Modernize the History module.
Comment #205
nevergonePlease testbot, needs review. :)
Comment #206
andypostBot failed on new code styles pre checks
Comment #207
daffie commentedAnd which one should be reviewed? The patch or the MR?
Comment #208
longwaveThe patch in #204 has some formatting issues, and the MR has deprecations referring to 9.1.x but these will need to be bumped to 9.2.x now. Not sure which of the patch and MR is most up to date here.
Comment #209
andypostUpdated MR and fixed it for 9.2
fixed deprecation
patch is broken
Comment #211
andypostFor some reason CI fails, trying as a patch from last rebase
Comment #214
daffie commentedThe patch looks good. A couple of minor points:
Technically we are doing a BC here. Only when I do a search on http://grep.xnddx.ru/search?text=_last_viewed&filename=, nobody is making use of the functionality.
I think we missed the 9.2 release window, therefore it should be changed to 9.3.
This needs to be updated to 9.3.
The variable both need their own line.
Can we change the variable name to $timestamp to be in line with the other ones in this file.
Comment #215
andypostUnpublished patch as MR used and rebased it against 9.3.x
Comment #216
berdirThis is a tough one. It's mixing making this a service, with restructuring the storage, caching with a memory cache service all in a single issue. No wonder this has been going since 2013 ;)
First, not fond of the cache tags. The entity cache tag is actually missing the entity type so that's kinda broken and both entity and user cache tags are only invalidated if a user or entity is deleted. That's pointless as nobody is going to request that information then. If we want to use a memory cache for this and not just a protected property (why, exactly?) then this actually seems like a good case to instantiate a separate bin and _not_ misuse the entity service, then you can just deleteAll() and be done with it.
Unsure about the storage changes. We can't add add the service now and add support for other entity types later, that's clear, but it makes what should be a fairly trivial issue many times as complicated. Kinda serious suggestion: Keep the API, but the default implementation would throw an exception on anything but node being passed in. Then either contrib or a follow-up issue later on could fill in the gaps.
Comment #217
nevergoneWhat can be done to move this forward?
Comment #218
andypostI like steps in #216 - let's split it somehow
Comment #220
jonathanshawI disagree with this reason, it severely limits the functioning of the API for very little benefit. I have a custom use case that needs to specify the user.
Comment #221
jonathanshawI agree with #216 that the scope of this issue has been unworkable. I have created a set of child issues and turned this into a meta:
#3267010: Introduce a generic HistoryRepository service without changing storage or caching
#3267011: [PP1] Use the HistoryRepository in the comment & node modules
#3267021: Deprecate history procedural functions
#3267014: Block & migrate tests fail to declare dependency on history
#3267015: Make History storage support any entity type
#3267016: Support history in views for entity types other than node
#3267019: Make history's frontend code support non-node entity types
#3267020: Use caching for history
I will create MRs on those issues with bits of the code from this issue.
Comment #222
berdirI'm not sure if you can split the first 3 tasks like that. That would result in a parallel API that is not used yet, which would in turn also require duplicated tests. Likely makes sense to introduce the service, replace all current usages and deprecate the existing functions at once?
Comment #223
jonathanshawThere is no existing test coverage of the existing procedural API, so maybe we wouldnt need to create duplicate test coverage.
Comment #224
geek-merlinI agree with @jonathanshaw that we need to agree on a battle plan, and with @berdir, that the exact split of issues is debatable.
Added #3274480: Make history repository optionally support "edit" besides "view" to the wishlist, of course open to dabate.
Also i feel this might win from maturing in contrib.
Comment #225
andypost++ to split, it will help to commit while D10 minors
Comment #229
andypostHistory module is going to contrib to iterate faster #3520462: [meta] Tasks to deprecate the History module
Comment #230
quietone commentedThe History Module was approved for removal in #3336276: [Policy] Deprecate History module.
This is Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.
The deprecation work is in #3520462: [meta] Tasks to deprecate the History module and the removal work in #3520468: [meta] Tasks to remove History module.
History will be moved to a contributed project after the Drupal 12.x branch is open.
Comment #231
needs-review-queue-bot commentedUpdated MR target branch from 11.x to main branch.
Comment #232
longwave