git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv5 03/17] gitweb/lib - Very simple file based cache

From
Thomas Adam <thomas@xteddy.org>
Date
Oct 6, 2010, 23:12 UTC
Message-ID
<AANLkTikVmHgk=jLCs11tJ7yhUL4H2gnM_pKkXOJSxYq7@mail.gmail.com>
In-Reply-To
<201010070100.33478.jnareb@gmail.com>
Hi --
On 7 October 2010 00:00, Jakub Narebski <jnareb@gmail.com> wrote:
> Thank you very much for those comments on code.
Sure.
> On the other hand this way scope where "no strict 'refs';" is active
> is limited... but I guess having "no strict 'refs';" outside loop would
> be better.
Definitely.
Show 10 quoted lines
>>
>> > +       my $file = $self->path_to_key($key);
>> > +       return undef unless (defined $file && -f $file);
>>
>> PBP (Perl Best Practises) will tell you that explicitly returning
>> undef is discouraged -- "undef" should be reserved for those errors
>> you cannot handle, not ones you don't want to.
>
> Well, Perl Best Practices are practices; sometimes there is good reason
> to not take them into account (though probably not in this case).

Do not ever underestimate Conway's book, Jakub -- seriously. It's not a Bible, sure, but to ignore it or otherwise eschew its advise is to shoot yourself in the foot. :)

> I should really have run gitweb, caching modules and tests through
> perlcritic...
And your other patches.   :)
Show 15 quoted lines
>> > +               last if $read_cnt == 0;
>> > +               $size_left -= $read_cnt;
>> > +               #last if $size_left <= 0;
>> > +       }
>> > +
>> > +       close $read_fh
>> > +               or die "Couldn't close file '$file' opened for reading: $!";
>> > +       return $buf;
>> > +}
>>
>> "use Carp;" would be more useful here, and hence croak() and confess().
>
> For a web application we usually do not want to have too detailed error
> message present to client (to web browser) to avoid leaking of sensitive
> information.

Unless we use fatalstobrowser, it will still end up in Apache's error log. I don't see a problem here.

Show 11 quoted lines
>> > +       # ensure that directory leading to cache file exists
>> > +       if (!-d $dir) {
>> > +               eval { mkpath($dir, 0, 0777); 1 }
>> > +                       or die "Couldn't create leading directory '$dir' (mkpath): $!";
>> > +       }
>>
>> Why is this eval()ed?  It will still return false and set $! appropriately.
>
> IIRC mkpath *dies on error*, rather than returning false.  For better
> error handling we would need to use make_path, but File::Path 2.0+
> is in [stable] core only since Perl 5.10.
Umm, maybe.   I've not verified this, but we shouldn't rely on this either.
> I don't want to code too defensively, but perhaps check for this is in
> order... though what we should do if $code is not code reference?

confess() ahem, or otherwise die() since it's a complete fail here. Appropriate logging is necessary here.

Show 5 quoted lines
>>
>> unless( defined $code and ref $code eq 'CODE' )
>
> "ref($code) eq 'CODE'" would be enough; 'undef' is not reference, and
> ref(undef) returns "".

Sure, but it still assumes $code is a reference, and there's no guarantee of that in the code path.

Show 7 quoted lines
>> {
>>         ....
>> }
>>
>> Wouldn't it be easier to eval{} this and check $@?
>
> So the answer is no.
Fantastic!   :)
-- Thomas Adam
Previous: Jakub NarebskiNext: Jakub Narebski
Message 10 of 41 in “[PATCHv5 00/17] gitweb: Simple file based output caching”
  1. Jakub NarebskiOct 6, 2010
  2. 01/17 t/test-lib.sh: Export also GIT_BUILD_DIR in test_externalJakub Narebski, Oct 6, 2010
  3. 02/17 gitweb: Prepare for splitting gitwebJakub Narebski, Oct 6, 2010
  4. 03/17 gitweb/lib - Very simple file based cacheJakub Narebski, Oct 6, 2010
  5. Thomas AdamOct 6, 2010
  6. Ævar Arnfjörð BjarmasonOct 6, 2010
  7. Thomas AdamOct 6, 2010
  8. Ævar Arnfjörð BjarmasonOct 6, 2010
  9. Jakub NarebskiOct 6, 2010
  10. Thomas AdamOct 6, 2010
  11. Jakub NarebskiOct 6, 2010
  12. Ævar Arnfjörð BjarmasonOct 6, 2010
  13. Jakub NarebskiOct 6, 2010
  14. 04/17 gitweb/lib - Stat-based cache expirationJakub Narebski, Oct 6, 2010
  15. 05/17 gitweb/lib - Regenerate entry if the cache file has size of 0Jakub Narebski, Oct 6, 2010
  16. 06/17 gitweb/lib - Simple select(FH) based output captureJakub Narebski, Oct 6, 2010
  17. Thomas AdamOct 6, 2010
  18. Jakub NarebskiOct 6, 2010
  19. Ævar Arnfjörð BjarmasonOct 6, 2010
  20. Jakub NarebskiOct 6, 2010
  21. 07/17 gitweb/lib - Cache captured output (using get/set)Jakub Narebski, Oct 6, 2010
  22. 08/17 gitweb: Add optional output cachingJakub Narebski, Oct 6, 2010
  23. Ævar Arnfjörð BjarmasonOct 6, 2010
  24. Jakub NarebskiOct 6, 2010
  25. Ævar Arnfjörð BjarmasonOct 6, 2010
  26. 09/17 gitweb/lib - Adaptive cache expiration timeJakub Narebski, Oct 6, 2010
  27. 10/21 gitweb/lib - Use CHI compatibile (compute method) caching interfaceJakub Narebski, Oct 6, 2010
  28. 11/17 gitweb/lib - Use locking to avoid 'cache miss stampede' problemJakub Narebski, Oct 6, 2010
  29. 12/17 gitweb/lib - No need for File::Temp when lockingJakub Narebski, Oct 6, 2010
  30. 13/17 gitweb/lib - Serve stale data when waiting for filling cacheJakub Narebski, Oct 6, 2010
  31. 14/17 gitweb/lib - Regenerate (refresh) cache in backgroundJakub Narebski, Oct 6, 2010
  32. 15/17 gitweb: Introduce %actions_info, gathering information about actionsJakub Narebski, Oct 6, 2010
  33. 16/17 gitweb: Show appropriate "Generating..." page when regenerating cacheJakub Narebski, Oct 6, 2010
  34. 17/17 gitweb: Add startup delay to activity indicator for cacheJakub Narebski, Oct 6, 2010
  35. 18/17 gitweb/lib - Add clear() and size() methods to caching interfaceJakub Narebski, Oct 6, 2010
  36. Thomas AdamOct 6, 2010
  37. 19/17 gitweb: Add beginnings of cache administration pageJakub Narebski, Oct 6, 2010
  38. 20/17 gitweb/lib - Benchmarking GitwebCache::SimpleFileCache (in t/9603/)Jakub Narebski, Oct 6, 2010
  39. 21/17 gitweb/lib - Alternate ways of capturing outputJakub Narebski, Oct 6, 2010
  40. [RFD] Possible improvements for output caching in gitwebJakub Narebski, Oct 10, 2010
  41. J.H.Oct 24, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.