hluk / CopyQ

Clipboard manager with advanced features
GNU General Public License v3.0
8.63k stars 440 forks source link

Maximum text length #2144

Open Fabian42 opened 1 year ago

Fabian42 commented 1 year ago

Yesterday I handled a large amount of files. Dolphin always writes a list of paths to the clipboard when copying/cutting files, so I got a huge entry into CopyQ that shows up on pretty much every search and lags out the UI. (For some reason I even got hundreds of these entries, but that might not be a CopyQ issue. But it did happen before with some automation, making this problem worse.) I found no way to get rid of these, since the entries seem to be stored in ~/.config/copyq/copyq_tab_JmNsaXBib2FyZA==.dat (what a filename…), a 9.2GB binary file that nothing I know can edit, also the export fails because of this size (I think it would need ≥18.4GB RAM) and there seems to be no way to mass-delete entries from within CopyQ. The only solution I found was to nuke the entire history. But a much better way would be to not have this problem at all, by being able to set a maximum length for text, just like there is one for the maximum size of images. (There's probably a way to do this with auto-commands, but I don't know it.)

P.S.: Respect to CopyQ for pretty much never crashing or fully freezing, even when confronted with ridiculous amounts of data, it always recovered eventually!

Grisgruis commented 5 months ago

+1, running into the same issue

hluk commented 5 months ago

I think this should be less of an issue in CopyQ 8.0.0 since it stores large items in a separate files and loads them only when needed - but search might be still slow though.

Here is a script that removes large items (can be run from Action dialog - F5 shortcut - but not sure about the memory requirements):

copyq:
// remove any item larger than 1MiB
sizeThreshold = 1 * 1024 * 1024;

sel = ItemSelection().selectAll();

notMatching = [];
for (var i = 0; i < sel.length; ++i) {
    const item = sel.itemAtIndex(i);
    const size = pack(item).length;
    if (size < sizeThreshold)
        notMatching.push(i);
}

sel.deselectIndexes(notMatching);
popup(`Removing ${sel.length} items`);
sel.removeAll();

There is the Big Data Tab command that would store large items in a separate tab. If you replace the last line (setData(mimeOutputTab, tabName)) with ignore(), it would not store the items at all.

I should probably add some reasonable size limits to the application.

Grisgruis commented 5 months ago

That was exactly what I was looking for!, thanks!