<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>466257</bug_id>
          
          <creation_ts>2023-02-22 19:50:09 +0000</creation_ts>
          <short_desc>Wrong calculation of cache size?</short_desc>
          <delta_ts>2023-02-26 12:07:22 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>2</classification_id>
          <classification>Applications</classification>
          <product>konqueror</product>
          <component>general</component>
          <version>Git</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Karl Ove Hufthammer">karl</reporter>
          <assigned_to name="Konqueror Bugs">konqueror-bugs-null</assigned_to>
          <cc>posta</cc>
          
          <cf_commitlink>https://invent.kde.org/network/konqueror/commit/979560661500f83f04e63d26e94d0531c9a5f52e</cf_commitlink>
          <cf_versionfixedin></cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2210769</commentid>
    <comment_count>0</comment_count>
    <who name="Karl Ove Hufthammer">karl</who>
    <bug_when>2023-02-22 19:50:09 +0000</bug_when>
    <thetext>I took a look at the source code in konqueor/settings/konqhtml/cache/cache.cpp, and the following two lines look wrong to me:

In void Cache::load():
    //Ensure that maxSizeInMB is greater than 0 if maxSizeInBytes is not 0
    int maxSizeInMB = maxSizeInBytes == 0 ? 0 : std::max(1, maxSizeInBytes / 1000);

In void Cache::save():
    //We store the size in bytes, not in MB
    grp.writeEntry(&quot;MaximumCacheSize&quot;, m_ui-&gt;cacheSize-&gt;value()*1000);

If you divide the number of bytes by 1000, you get kB, *not* MB. Similarly, if you multiply an MB value by 1000, you get the number of kB, not the number of bytes.

In the UI (cache.ui), the suffix is set to ‘ MB’. So either the calculation should be changed to divide/multiply by 1000^2, or the UI string should be changed to ‘ kB’, or, preferably, to use the correct KFormat feature for proper formatting (https://api.kde.org/frameworks/kcoreaddons/html/classKFormat.html).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2211855</commentid>
    <comment_count>1</comment_count>
    <who name="Stefano Crocco">posta</who>
    <bug_when>2023-02-26 10:33:05 +0000</bug_when>
    <thetext>(In reply to Karl Ove Hufthammer from comment #0)
&gt; I took a look at the source code in
&gt; konqueor/settings/konqhtml/cache/cache.cpp, and the following two lines look
&gt; wrong to me:
&gt; 
&gt; In void Cache::load():
&gt;     //Ensure that maxSizeInMB is greater than 0 if maxSizeInBytes is not 0
&gt;     int maxSizeInMB = maxSizeInBytes == 0 ? 0 : std::max(1, maxSizeInBytes /
&gt; 1000);
&gt; 
&gt; In void Cache::save():
&gt;     //We store the size in bytes, not in MB
&gt;     grp.writeEntry(&quot;MaximumCacheSize&quot;, m_ui-&gt;cacheSize-&gt;value()*1000);
&gt; 
&gt; If you divide the number of bytes by 1000, you get kB, *not* MB. Similarly,
&gt; if you multiply an MB value by 1000, you get the number of kB, not the
&gt; number of bytes.
&gt; 
&gt; In the UI (cache.ui), the suffix is set to ‘ MB’. So either the calculation
&gt; should be changed to divide/multiply by 1000^2, or the UI string should be
&gt; changed to ‘ kB’, or, preferably, to use the correct KFormat feature for
&gt; proper formatting
&gt; (https://api.kde.org/frameworks/kcoreaddons/html/classKFormat.html).

Thanks for pointing this out. The conversion factor is clearly wrong and I&apos;ll fix it immediately. I&apos;m not sure, instead, about using KFormat here. As far as I can see, KFormat only returns a string representation of the number converted to the appropriate unit, but this won&apos;t be useful here, as I need to put the value inside a QSpinBox, which only accepts numbers. Of course I could use KFormat to convert a dummy value, then extract the unit from the string, but I&apos;m not sure it&apos;s worth doing so. Could you please clarify your suggestion?

Thanks</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2211876</commentid>
    <comment_count>2</comment_count>
    <who name="Stefano Crocco">posta</who>
    <bug_when>2023-02-26 11:27:12 +0000</bug_when>
    <thetext>Git commit 979560661500f83f04e63d26e94d0531c9a5f52e by Stefano Crocco.
Committed on 26/02/2023 at 11:27.
Pushed by stefanocrocco into branch &apos;master&apos;.

Use the correct conversion factor

M  +4    -2    settings/konqhtml/cache/cache.cpp

https://invent.kde.org/network/konqueror/commit/979560661500f83f04e63d26e94d0531c9a5f52e</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2211877</commentid>
    <comment_count>3</comment_count>
    <who name="Karl Ove Hufthammer">karl</who>
    <bug_when>2023-02-26 11:35:25 +0000</bug_when>
    <thetext>(In reply to Stefano Crocco from comment #1)
&gt; Thanks for pointing this out. The conversion factor is clearly wrong and
&gt; I&apos;ll fix it immediately. I&apos;m not sure, instead, about using KFormat here. As
&gt; far as I can see, KFormat only returns a string representation of the number
&gt; converted to the appropriate unit, but this won&apos;t be useful here, as I need
&gt; to put the value inside a QSpinBox, which only accepts numbers. Of course I
&gt; could use KFormat to convert a dummy value, then extract the unit from the
&gt; string, but I&apos;m not sure it&apos;s worth doing so. Could you please clarify your
&gt; suggestion?

Hmm, I’m not actually sure what the best solution is. The idea was that the spinbox would support the BinaryUnitDialect setting (see bug 364321), so  that spinbox should hold the number of *bytes*, but would be formatted as &apos;kB’, ‘KIB’ or ‘KB’ (or ‘MB’/‘MiB’) depending on the user‘s BinaryUnitDialect settings (and with the proper conversion factor, e.g. 1000 or 1024).

But this is complicated to implement, and it’s not a good idea that every program with a ‘byte spinbox’ should have a complicated workaround for handling it. There really should be a general ByteSpinBox that would handle this automatically. (See also bug 453853 for a similar problem in Dolphin.) For now, I guess it’s OK to have the text hardcoded as ‘MB’.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2211887</commentid>
    <comment_count>4</comment_count>
    <who name="Karl Ove Hufthammer">karl</who>
    <bug_when>2023-02-26 12:07:22 +0000</bug_when>
    <thetext>BTW, thanks for fixing this bug. And I’ve added a bug report (bug 466468) for general spinbox support for formatting of byte values.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>