Skip to content

Tag and untag multiple resources at once

  • change tagResource to tagResources and accept a QVector of resource ids instead of just one resource id
  • change untagResource to untagResources and accept a QVector of resource ids instead of just one resource id
  • in untagResource, just update all rows (from active = 1 to 0) everything within a transaction and then use resetQuery after all is untagged
  • in tagResource, either update the rows (when the row representing both the tag and the resource are already present in the database) or add new rows; do both in transactions
  • calculate values for indices in beginInsertRows and beginRemoveRows:
    • run the main query, with either only active rows or both active and inactive rows
    • remember all places where the rows will be added or removed
    • then run beginInsertRows or beginRemoveRows as many times as needed (note that they can only take one range, so in case the rows to remove or insert are interweaven with rows that will stay, the functions must be run multiple times)
    • note that the indices in beginInsertRows and beginRemoveRows have rules on how the values of indices accumulates when those functions are used multiple times before one endXRows is run
    • note that the endXRows must be run exactly the same amount of times as beginXRows
  • add unit tests for the begin and end signals, so in case of any changes in the future, it can be checked for correctness

Consequence for the user

  • tagging and untagging multiple resources is fast now; in a lot of cases it would be instant, there might be not instant cases but only if the database (precisely, tags_resources table) is very big - but before, an operation that could take several minutes, now takes nearly instant, so it's much better (even 140x speed increase in my tests)
  • signals are correct now, they weren't before; I hope it will fix bug 448359 (https://bugs.kde.org/show_bug.cgi?id=448359).

Test Plan

  • run all tests in libs/resources/tests, all should pass (now even TestTagFilterProxyModel should pass! Despite me not doing anything to fix it, except fixing the signals)
  • Import Rakurri's bundle (latest one) and:
    • change the storage to Rakurri's bundle
    • select all resources (all other actions do on all resources)
    • add 8 tags: rak1, rak2, rak3, etc. to rak8 (they should be somewhat instant after my changes)
    • remove rag5 and rak6, add them again - should be instant again (might be a bit slower than adding fresh)
    • unselect resources; select some resources, then leave some space and select another set of resources; tag them with rak9, then see if all of them show up when switching to rak9

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.
Edited by Agata Cacko

Merge request reports