Skip to content
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

Make it possible to filter for unused media elements #1005

Closed
timobrembeck opened this issue Oct 30, 2021 · 4 comments · Fixed by #2048
Closed

Make it possible to filter for unused media elements #1005

timobrembeck opened this issue Oct 30, 2021 · 4 comments · Fixed by #2048
Assignees
Labels
‼️ prio: high Needs to be resolved ASAP. 💡 feature New feature or request 😅 effort: medium Should be doable in <12h
Milestone

Comments

@timobrembeck
Copy link
Member

Motivation

In the media library, it should be possible to filter for all media elements which are not embedded in any pages/events/pois and are not used as icon of any object.

Proposed Solution

Evaluate possible approaches for this task, e.g. whether we should store this information somewhere in the database and update it every time a media element is inserted into a page, or whether this should be "calculated" at runtime by scanning the whole content for occurrences of the media file's absolute paths.

Alternatives

Additional Context

@timobrembeck timobrembeck added 💡 feature New feature or request ⁉️ prio: low Not urgent, can be resolved in the distant future. labels Oct 30, 2021
@timobrembeck timobrembeck added this to the Version 2.0 milestone Oct 30, 2021
@ulliholtgrave
Copy link
Member

I agree that this should be come in handy, but as for the migration we can focus on only migrating used media files. Therefore, I would leave it on the Version 2.0 milestone.

@svenseeberg svenseeberg modified the milestones: Version 1.2, Version 1.3 Apr 27, 2022
@ulliholtgrave ulliholtgrave added the 😅 effort: medium Should be doable in <12h label May 16, 2022
@svenseeberg svenseeberg added ‼️ prio: high Needs to be resolved ASAP. and removed ⁉️ prio: low Not urgent, can be resolved in the distant future. labels Jun 7, 2022
@svenseeberg svenseeberg modified the milestones: 22Q3, 22Q4 Jun 7, 2022
@JanErikHuehne
Copy link
Contributor

Is there any consent on how this should be implemented? Scanning at runtime sounds very slow to me. So should we only perform this one time scan during migration and add fields to media files that get set if they are added / removed somewhere? Maybe a decorator implementation to all functions involving media files might be a good idea to check it? Otherwise, there will a lot of redundant code I assume.

@JanErikHuehne JanErikHuehne pinned this issue Nov 1, 2022
@timobrembeck
Copy link
Member Author

Actually, the information is already stored in the database implicitly by our broken link checker.
So all we would have to do is count how many Link objects exist with the URL to the media element, e.g.

$ pipenv run integreat-cms-cli shell --settings=integreat_cms.core.docker_settings
Python 3.9.15 (main, Oct 26 2022, 16:20:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from integreat_cms.cms.models import *

In [2]: from linkcheck.models import *

In [3]: m = MediaFile.objects.first()

In [4]: m.url
Out[4]: 'http://localhost:8000/media/regions/1/2022/11/php.png'

In [5]: url = Url.objects.get(url=m.url)

In [6]: url
Out[6]: <Url: http://localhost:8000/media/regions/1/2022/11/php.png>

In [7]: {link.content_object for link in url.links.all()}
Out[7]: {<PageTranslation (id: 731, page_id: 21, language: de, slug: alltag)>}

This gets all usages in the content, and then we probably want to additionally count the usages as icon, but this is even simpler:

In [8]: m.icon_organizations.all()
Out[8]: <QuerySet []>

In [9]: m.icon_regions.all()
Out[9]: <QuerySet []>

In [10]: m.events.all()
Out[10]: <EventQuerySet []>

In [11]: m.pages.all()
Out[11]: <PageQuerySet []>

In [12]: m.events.all()
Out[12]: <EventQuerySet [<Event (id: 1, region: augsburg, slug: test-veranstaltung)>]>

In [13]: m.pois.all()
Out[13]: <ContentQuerySet []>

And since it's so easy, it probably also makes sense to directly show the first 1-2 objects where it's used in the sidebar of the media library, in case users want to directly edit the page where the image is used.

@JanErikHuehne
Copy link
Contributor

I see. I´m on it. Thanks for the input 👍

@JanErikHuehne JanErikHuehne self-assigned this Nov 1, 2022
@timobrembeck timobrembeck unpinned this issue Nov 10, 2022
@timobrembeck timobrembeck modified the milestones: 22Q4, 23Q1 Dec 12, 2022
@JanErikHuehne JanErikHuehne removed their assignment Jan 2, 2023
@MizukiTemma MizukiTemma self-assigned this Jan 30, 2023
This was referenced Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
‼️ prio: high Needs to be resolved ASAP. 💡 feature New feature or request 😅 effort: medium Should be doable in <12h
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants