-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
EntityRepository is fetching all property data for media #3460
Conversation
…epository/service without fetching all property data. ensures the trees use this method to avoid fetching property data in the media tree.
I think for a v7 'quick fix' we can accept that this is hacky and a work around. For v8 i think we need to fix this:
This would cleanup a huge portion of this code |
@Shazwazza I'm good with calling this a 'quick fix' and also know that we should fix it differently for V8. |
@Shazwazza one thing i don't understand, if you need properties on a media item, why not use the media service? The whole point of the entity service/repository was to load the bare minimum of what makes it an entity and thus without properties. If the media item contains a property that is essential to its 'entity' then why not look at that first, so entities can remain entities. |
@sitereactor many many moons ago when this was done, the EntityService was used for things that it didn't support because it was assumed that media and content were almost the 'same'. As it turns out when we went down this path, they weren't the same, things like URLs and dimensions were needed for the most basic media item. We then went down a path to treat some entities differently than others with this service because we needed to use it to be able to lookup the basic requirements of media. (it's been a very long time, i cannot tell you exactly the entire story) We figured out we could load the property values and media values in a single query, because it was a single query it was perceived that the performance was going to be good (oh how we learn new things over time ;) Obviously this was not the case but it was never changed because there was never seemed to be a side affect. Of course now there is and with all things learned we will need to fix it properly eventually. If we used the Media Service for loading the tree, it would be worse. |
I'm sure the past has its reasons and that is fine. I would much rather look ahead to see how we can fix it and improve future umbraco, and I think we are on the same page with your v8 suggestion. My point is just that maybe we should look at the various usages and what is required where and why, so we can keep the EntityService for what its meant for and so the usages where properties are not needed can use that happy path. Or expose suitable methods through the MediaService. Whatever you prefer. As long as its clear what you are getting from the various services/repositories/etc. |
Sure thing, just we can't change it (properly) in v7 now because of breaking changes and all that |
why are property data being loaded?I've Investigating this further with regards to where/why the media properties are requires. It seems that that most of the loading of property values for media with the EntityService is only required for very old legacy reasons which are not in use anymore, however there is still a couple of scenarios where this is still required:
So I believe this is really purely about resolving image file paths - though we can't only rely on the solutionssolution 1This PR work around seems OK and could work for the time being. I'll probably change the solution 2Another slightly more consistent solution for v7 which could be:
That said, this is a bunch more work and considering I don't think the solution 3Considering this is really only used to determine the media file path/url, we already now store this data in the database from 7.10 (? something like that) in the The problems with this are:
This is the most robust solution and would cause very little extra overhead for the entity queries. I propose we make this change in v8. v8 changesCleaning this up in v8 will take some work and will need to be done before 8.0 since it is breaking changes that cannot be unbroken in a minor version. We should implement solution 3 above which will mean
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The methods for media without properties should just be for media and named accordingly the rest could just stay as it was. I'll update so you can see changes.
@@ -331,24 +331,49 @@ public virtual IEnumerable<IUmbracoEntity> GetByQuery(IQuery<IUmbracoEntity> que | |||
return list; | |||
} | |||
|
|||
/// <summary> | |||
/// Gets entities by query. | |||
/// Note that this will also fetch all property data for media items, which can cause performance problems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This note should be in a block
bool isMedia = objectTypeId == Constants.ObjectTypes.MediaGuid; | ||
/// <summary> | ||
/// Gets entities by query without fetching property data. | ||
/// This is supposed to be internal and can be used when getting all entities without paging, without causing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also should be in a block
/// <param name="query"></param> | ||
/// <param name="objectTypeId"></param> | ||
/// <returns></returns> | ||
internal IEnumerable<IUmbracoEntity> GetByQueryWithoutPropertyData(IQuery<IUmbracoEntity> query, Guid objectTypeId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason to have the objectTypeId param here, this methods should just be called GetMediaByQueryWithoutPropertyData
Have added v8 task here #3498 |
connect #3457
Changes
This is not the prettiest way to do it since it requires casting of the service/repo to use the internal methods. It is however a way of preventing this becoming a breaking change in the APIs.
This should be fixed when merged to V8, to we make sure we do not do this in the
EntityRepository
for media items.Test