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

Delete specific attachments before save issue or comment #196

Open
DolezalDavid opened this issue Nov 5, 2020 · 8 comments
Open

Delete specific attachments before save issue or comment #196

DolezalDavid opened this issue Nov 5, 2020 · 8 comments

Comments

@DolezalDavid
Copy link

Hi,
i try long time to find solution, how delete specific attachmets before save issues or comments.

Reason is simple. I use email as the one of the ways how create or comment issues. And emails usually have some logo (like corporation logo, etc.) and I have database full of logos. :-)

I think it will be quite easy to manage it, but I don't see light in the end of tunnel now. I know size of file on disk or size in px...

Someone to help? :-)

@DolezalDavid
Copy link
Author

DolezalDavid commented Nov 5, 2020

What do you think about digest? Can I use it as indentificator for specific attachments? It looks it can work...

@DolezalDavid
Copy link
Author

DolezalDavid commented Nov 6, 2020

I'm ruby beginner, but how said Jan Amos Komensky:"Learn, learn, learn." I try some script in console and this is my start point:
Attachment.where(digest: '<hexadecimal_code>').ids
It turn me back aray of ids of pictures/logos

May be I can start like this?
if subject.present? if self.has_attachment? ...

Any ideas? @picman

@picman
Copy link
Collaborator

picman commented Nov 6, 2020

It has said Lenin.

@AirTibu
Copy link

AirTibu commented Nov 6, 2020

Hi David,

Set the observable object to "Issue Attachments":

image

Use the below code in AFTER SAVE. You can modify the file size limit by changing it in this section: "< 200.to_i.kilobytes".


if @attachment.filesize < 200.to_i.kilobytes
  if @attachment.container
    @attachment.container.attachments.delete(@attachment)
  else
    @attachment.destroy
  end
end

I hope its help!

@DolezalDavid
Copy link
Author

@picman Sorry. I made mistake... You have right.

@AirTibu It works nice. Thank you!

@DolezalDavid
Copy link
Author

if @attachment.filesize < 200.to_i.kilobytes
if @attachment.container
@attachment.container.attachments.delete(@attachment)
else
@attachment.destroy
end
end

Hi, I turn back to this problem. I applied your solution and on the first test looks good, but. If I send with company logo another attachment this script delete it also.

So I think about solution and here is my idea.

  1. find how many attachments are in container
  2. if there are more then one, check filesize one by one (for each?)
  3. if filesize = xyz kilobytes, then delete, else do nothing

The point of this is delete after save company logo which is always the same, ale slowly take some disc space...

What do you think about it?

Thanks.

David

@picman
Copy link
Collaborator

picman commented Sep 20, 2022

I cannot imagine how a logo < 200kB, although saved many time, can noticeably consume the disk space. I'd enlarge the disk space rather than implement such a hack.

@qawsed55
Copy link

I cannot imagine how a logo < 200kB, although saved many time, can noticeably consume the disk space. I'd enlarge the disk space rather than implement such a hack.
or user can run script on host machine periodicaly, that will finge full file duples and change each duplicate to symlink )

And as not to make many issuses, it will be nice to have more examples for users like me, that not good in Ruby or so )
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants