After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 397348 - new feature: preferences option to clear the article cache on exit
new feature: preferences option to clear the article cache on exit
Status: RESOLVED FIXED
Product: Pan
Classification: Other
Component: general
pre-1.0 betas
Other All
: Normal normal
: 1.0
Assigned To: Charles Kerr
Pan QA Team
Depends on:
Blocks:
 
 
Reported: 2007-01-16 18:46 UTC by Bruce Bowler
Modified: 2007-01-22 15:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to create a preference option to clear the article cache on exit (3.61 KB, patch)
2007-01-20 20:10 UTC, Darren Albers
none Details | Review
Patch to create an option to clear cache on exit & add a clear article cache option to the article menu (6.96 KB, patch)
2007-01-20 21:12 UTC, Darren Albers
needs-work Details | Review
Try #3 incorporating Charles recommendations (6.99 KB, patch)
2007-01-21 03:32 UTC, Darren Albers
committed Details | Review

Description Bruce Bowler 2007-01-16 18:46:10 UTC
In "old pan" it was possible to have pan clear the article cache on exit.  That feature has disappeared from "new pan".  This is a request to add that feature back.

See http://permalink.gmane.org/gmane.comp.gnome.apps.pan.user/8159 for more discussion and (my :-) justification
Comment 1 Darren Albers 2007-01-17 22:49:23 UTC
I am making a note here to take a look at this when I get home from California.   Some notes for myself:

In Pan "1" this was handled by sending a 0 size value to the function acache_expire_to_size

Can we do the same with Pan2 in article-cache.cc expire_to_size ()?
This function accepts no values and has a pointer to the value max_megs.  Since Pan seems to dynamically clear the cache when running I will probably need to copy most of this function into a new one to handle this that is called only when shutdown.

Charles if this all sounds too hackish let me know.

Comment 2 Darren Albers 2007-01-19 17:37:45 UTC
Charles, I am trying to follow the logic in the expire_to_size function and I have a quick question.  What is an "Active" cached article?
Comment 3 Charles Kerr 2007-01-19 19:24:17 UTC
If you're referring to the debug message at the end of expire_to_size(),
it's poor wording.  `active' would be better written here as `remaining'.
I agree with you about old Pan's approach.  We could have two functions,
expire_to_size(size_t) and expire_to_size():

  expire_to_size()
  {
    size_t max_bytes = ...;
    expire_to_size (max_bytes);
  }

  expire_to_size(size_t max_bytes)
  {
    quarks_t removed;
    ...
  }

  clear ()
  {
    expire_to_size (0);
  }


The rest of the work is adding a prefs-ui patch for toggling the flag,
and some code in pan.cc right before DataImpl goes out of scope 
to call cache.clear () if the prefs flag is set.

I'll probably be doing a release on Monday that badly breaks the
string freeze.  If you want to do a queue/prefs-ui/pan.cc patch
this weekend, attach it and I'll put it in the release.
Comment 4 Darren Albers 2007-01-20 00:23:28 UTC
That sounds good, I have a tentative patch now that I wrote on the plane but I think something is wrong with my logic since there are always a small number of remaining "Active" objects.  

I plan on diving deeper in it tonight and I hope to have something soon.

I was originally planning on just having the option in preferences.xml but I can easily add it to the preferences options in the GUI since you are breaking the string freeze anyway!
Comment 5 Darren Albers 2007-01-20 04:51:55 UTC
Ok something is odd about the function expire_to_size(), it never catches all the files.

If I do _mid_to_info.size() it returns the proper number of objects in cache, however when I run through the for loop that orders the files it does not pick up every file.  

However if I add a while (_mid_to_info.size()>0) at the top it eventually catches all the files.  So I /think/ something is wrong with the process by which articles are added to the set si of type sorted_info_t but I haven't been able to figure out what yet.

Charles, any ideas?  Am I just doing something stupid?
Comment 6 Darren Albers 2007-01-20 04:58:26 UTC
Steps to reproduce this:
hardcode max_bytes to 0, add a count to the for loop in expire_to_size() to count how many times it runs through.  Then do a _mid_to_info.size() and it is smaller almost everytime.

If you force it to run with a while(_mid_to_info.size()>0) it will eventually catch all the files...
Comment 7 Charles Kerr 2007-01-20 07:02:13 UTC
Ahhh, I think I know what's going on.  If two articles have the same
timestamp then they're considered to be equal by MsgInfoCompare.
Great work finding this bug... here's a patch that should fix it.

Index: article-cache.h
===================================================================
--- article-cache.h     (revision 91)
+++ article-cache.h     (working copy)
@@ -98,7 +98,9 @@
 
       struct MsgInfoCompare {
         bool operator()(const MsgInfo& a, const MsgInfo& b) const {
-          return a._date < b._date;
+          if (a._date != b._date)
+            return a._date < b._date;
+          return a._message_id < b._message_id;
         }
       };
 
As an aside, !_mid_to_info.empty() is better than _mid_to_info.size()>0,
since the former only needs to look for a first node, whil the latter
may have to walk the tree to count the nodes.
Comment 8 Darren Albers 2007-01-20 20:10:50 UTC
Created attachment 80771 [details] [review]
patch to create a preference option to clear the article cache on exit

First draft of patch to add an option to clear cache on exit.  

This is pretty simple, I copied the expire_to_size function into a new function called clear_cache_on_exit and call it when they user quits.

This patch doesn't work when someone hits alt-f4 and only when the user exits from the file menu.

Charles, what do you think about a clear cache option in the Articles menu for "on demand" clearing?
Comment 9 Darren Albers 2007-01-20 21:12:23 UTC
Created attachment 80775 [details] [review]
Patch to create an option to clear cache on exit & add a clear article cache option to the article menu

This patch is similar to the one above except it adds a "Clear Article Cache" selection to the articles menu.

Charles:
1) I incorporated your earlier patch into these two.
2) Is the Articles menu the appropriate place for this or would it be better suited for the file menu?
Comment 10 Charles Kerr 2007-01-21 00:44:48 UTC
The function shouldn't be called clear_on_exit(), since there's nothing
intrinsic in the function about "on exit".  It could clear at any time.

IMO the approach in Comment #3 would be better, since it would duplicate
less code.

It could work on both exit and alt-F4 if you move the flag test from gui.cc
to pan.cc between the two close braces on lines 297 and 298; that is, right
before the Prefs and Cache objects are destroyed by going out of scope at
the second close brace.

What are the use cases for on-demand clearing?
I'm not really against it but I don't see the need for it either...
Comment 11 Darren Albers 2007-01-21 01:03:09 UTC
I actually changed the name of the function to clear_cache in my second patch since I realized that it didn't make much sense.

Some people have asked how to clear the cache and currently the answer is to go to ~/home/.pan2/article-cache and delete everything which isn't user friendly.  This places it in an easy to find location.  I actually added this after a post today to the users mailing list asking where the cache was.

I think the use case is that a user has increased the size of his cache and wants to do a one-time clear after reading a large number of groups and doesn't want to hassle with:
a) Manually deleting the files, they may not know where it is
b) Setting it to clear on exit and then remember to uncheck that when they open it back up.
Comment 12 Darren Albers 2007-01-21 01:04:26 UTC
Oh and I will fix the exit issue and move it to pan.cc as you pointed out.  Thanks!
Comment 13 Darren Albers 2007-01-21 01:10:38 UTC
Can you clarify what you meant in comment#3?   I /think/ you are suggesting merging the two functions and then just passing the appropriate value to the function depending on what is required.  If so I'll take a look at that.

Sorry for the disjointed replies to this bug report.
Comment 14 Charles Kerr 2007-01-21 01:38:31 UTC
Since ArticleCache::clear() is as easy to understand as
ArticleCache::clear_cache(), IMO the function doesn't
need `cache' in the name either... but I'm just nitpicking
at this point. =)

Yes, I'm suggesting that there only be one function that
actually deletes the files, and that it take a size
argument a la 0.14.x.  This should be a private function,
and there should be two public ones, clear() and
expire_to_size(), pass the appropriate value to the
private function expire_to_size(size_t).
Comment 15 Charles Kerr 2007-01-21 01:39:10 UTC
No problem about the disjointed replies.
Comment 16 Darren Albers 2007-01-21 03:32:54 UTC
Created attachment 80797 [details] [review]
Try #3 incorporating Charles recommendations

This patch separates the clearing of the cache into two public and one private members, the private function handles all the file deletions as Charles suggested.   

expire_to_size sends the bytes to the private function expire_to_size
clear () sends 0 to the private function expire_to_size

Charles a few notes:
1) This patch includes your fix from comment #7
2) This patch also includes the addition of a clear cache option in the articles menu but if you don't feel it is necessary I can remove it.   However I think it is useful and should probably be present somewhere so users can clear their cache without the need to go outside pan.

Thank you for all the guidance Charles!
Comment 17 Charles Kerr 2007-01-21 05:45:31 UTC
Looks great!
Comment 18 Charles Kerr 2007-01-22 15:39:05 UTC
er, except main() doesn't take a Prefs&, but still... =)