- Issue created by @olivier.bouwman
- π³π±Netherlands johnv
Indeed,
the code is needed to be able to create subclasses of the OfficeHours item.
I find the API very hard to handle.
Perhaps there is a better way to create those special items. I did not check the commit, yet.Do you encounter the problem after an upgrade, and did it work in an older version? I might check if the commit can be reversed.
- π³π±Netherlands johnv
Checking the commit, the buffer makes that the ::create() is called only once per page request. Without, it will be triggered upon every Exception/Season time slot.
I guess it will not be triggered when the page is fetched from cache.So adding the buffer will add performance, but will not remove the create. Unless you have problem with the 'many' calls, and do not mind the buffered 'one-time' call?
- πΊπΈUnited States olivier.bouwman Portland, Oregon
Do you think an approach like this can work? It seems to work from my limited testing.
(excuse my patch file, I can do a merge request if needed) - π³π±Netherlands johnv
No need for MR. I do not understand them. I am not sure how your patch works.
Some remarks on your patch:
The problem, IIUC, is FieldConfig::create() for every exception, season item. That can be reduced to 1 time per page by bringing back the buffer, but I do not think that it will solve your problem.
There is no actual field change happening, I only want to have several subclasses of OfficeHoursItem in the ItemList.I do not understand how the cache service helps. It does invalidates your cache, too, Not?
At first glance it might help to refresh stale field caches, for which several issues exist. However, a chache is also invalid when a opening/closing time passes.We should investigate how we can 'hide' this creation for other modules. Some core functions have this '$notify' parameter. Or is that exaclty the point of you cache service?
- πΊπΈUnited States olivier.bouwman Portland, Oregon
The problem, IIUC, is FieldConfig::create() for every exception, season item. That can be reduced to 1 time per page by bringing back the buffer, but I do not think that it will solve your problem.
There is no actual field change happening, I only want to have several subclasses of OfficeHoursItem in the ItemList.I do not understand how the cache service helps. It does invalidates your cache, too, Not?
At first glance it might help to refresh stale field caches, for which several issues exist. However, a chache is also invalid when a opening/closing time passes.Correct, caching on a per page basis would not help with this issue. The cache solution I used is persistent across page loads, it is permanent until the field config is saved or a manual cache clear is done.
Whenever FieldConfig::create runs, any hook_entity_create will run (like jsonapi_entity_create). I don't think this is desired or needed.
The caching approach I went with causes the field config to be saved permanently for each combination of:
- entity_type (node for example)
- bundle (location for example)
- field_name (field_open_hours for example)
- field_type (office_hours_exceptions, office_hours_season_header, office_hours_season_item)
Whenever the field config for any of the related fields is saved (through /admin/structure/types/manage/location/fields/node.location.field_open_hours in our example), the related cache tag is invalidated and FieldConfig::create will run on the next page load to catch any changes.I tested with multiple nodes with multiple exception hours per node. Exception hours show correctly and jsonapi_entity_create is no longer triggered.
Is there a reason to run FieldConfig::create once per page load? I don't see why that would be desired.
Can you think of any test I could do that would help us understand this better or ensure this solution works for other use-cases?> We should investigate how we can 'hide' this creation for other modules. Some core functions have this '$notify' parameter. Or is that exaclty the point of you cache service?
I don't think this is necesarry as long as we can limit the FieldConfig::create to be done infrequently (not on every page load).