about summary refs log tree commit homepage
path: root/lib/PublicInbox
DateCommit message (Collapse)
2020-01-24mid: shorten uniq_mids logic
We won't be able to use List::Util::uniq here, but we can still shorten our logic and make it more consistent with the rest of our code which does similar things.
2020-01-24inbox: simplify filtering for duplicate NNTP URLs
And add a note to remind ourselves to use List::Util::uniq when it becomes common.
2020-01-24nntp: simplify setting X-Alt-Message-ID
We can cut down on the number of operations required using "grep" instead of "foreach".
2020-01-24contentid: use map to generate %seen for Message-Ids
This use of map {} is a common idiom as we no longer consider the Message-ID as part of the digest.
2020-01-23hval: from_attr: move to unit test
We don't call from_attr anywhere outside of tests, so don't bloat normal processes with it.
2020-01-23hval: to_attr: support wide characters
We need to escape wide characters when making attribute names from filename-looking things in diffstats.
2020-01-13sigfd: simplify loop and improve documentation
We can use the return value of sysread to bound our loop instead of repeatedly shortening the string. Furthermore add some comments which can be easily checked against the signalfd(2) manpage.
2020-01-13ds: flatten $EXPMAP, delete entries on close
We can reduce the amount of small arrayrefs in memory by flattening $EXPMAP. This forces us to properly clean up references during deferred close handling, so NNTP (and soon HTTP) connections no longer linger until expiry.
2020-01-13ds: rely on autovivification for $later_queue
No reason to have an empty arrayref lying around when not everybody needs it. Re-indent the later-related subs since we're changing a bunch of lines, anyways.
2020-01-13ds: rely on autovivication for waitpid bits
No need to create an arrayref until we need it, and fix up a comment while we're in the area. Some aesthetic changes while we're at it: - Rename $WaitPids to $wait_pids to make it clear this is unique to our implementation and not in Danga::Socket. - rewrite dwaitpid() to reduce indentation level
2020-01-13ds: rely on autovivification for nextq
Another place we can delay creating arrays until needed.
2020-01-13ds|http|nntp: simplify {wbuf} population
We can rely on autovification to turn `undef' value of {wbuf} into an arrayref. Furthermore, "push" returns the (new) size of the array since at least Perl 5.0 (I didn't look further back), so we can use that return value instead of calling "scalar" again.
2020-01-13ds: guard ToClose against DESTROY side-effects
This does not affect our current code, but theoretically a DESTROY callback could call PublicInbox::DS::close to enqueue elements into the ToClose array. So take a similar strategy as we do with other queues (e.g. $nextq) by swapping references to arrays, rather than operating on the array itself. Since close operations are relatively rare, we can rely on auto-vivification via "push" ops to create the array on an as-needed basis. Since we're in the area, clean up the PostLoopCallback invocation to use the ternary operator rather than a confusing (to me) combination of statements. Finally, add a prototype to strengthen compile-time checking, and move it in front of our only caller to make use of the prototype.
2020-01-13ds: remove Timer->cancel and Timer class+bless
It doesn't seem needed at the moment, and we can re-add it in the future if needed.
2020-01-13ds: add an in_loop() function for Inbox.pm use
Inbox.pm accessing the $in_loop variable directly raises warnings when Inbox is loaded without DS.
2020-01-13ds: add_timer: rename from AddTimer, remove a parameter
The class parameter is pointless, especially for an internal sub which only has one external caller in a test. Add a sub prototype while we're at it to get some compile time checking.
2020-01-13ds: new: avoid redundant check, make clobbering fatal
"fileno(undef)" already dies under "use strict", so there's no need to check for it ourselves. As far as "fileno($closed_io)" or "fileno($fake_io)" goes, we'll let epoll_ctl detect the error, instead. Our design should make DescriptorMap entries impossible to clobber, so make it fatal via confess in case it does happen, because inadvertantly clobbering a FD would be very bad. While we're at it, remove a redundant return statement and rely on implicit returns.
2020-01-13use popen_rd for bidirectional pipes
popen_rd accepts arbitrary redirects, so we can reuse its code to setup the pipe end we want to read, saving each caller a few lines of code compared to calling pipe+spawn.
2020-01-13xapcmd: use popen_rd for running xapian-compact
public-inbox-compact wrapper displays progress by default, anyways, and there's not a lot of output, so simplify our code by using popen_rd instead of spawn + optional pipe. While we're at it use "while (<HANDLE>)" to display progress as it happens, since "foreach (<$HANDLE>)" slurps the contents into an array, first.
2020-01-13cgit: drop cgit_parse_hdr wrapper
Unlike PublicInbox::GitHTTPBackend::git_parse_hdr, cgit_parse_hdr does nothing interesting besides calling parse_cgi_headers. So just make a reference to PublicInbox::GitHTTPBackend::parse_cgi_headers and call it.
2020-01-13solver: path_a may be undef from /dev/null
This avoids uninitialized variable warnings when viewing newly-created files.
2020-01-13git: packed_bytes: use GLOB_NOSORT
File::Glob is loaded by the perl for the "glob()" op, anyways, so call bsd_glob with the GLOB_NOSORT to avoid needless sorting of the output.
2020-01-13git: modified: don't slurp `rev-parse --branches'
While v1 inboxes typically only have one branch, code repositories may have dozens or even hundreds. Slurping those into memory is a waste.
2020-01-13config: do not slurp entire cgitrc at once
cgitrc files can have hundreds or thousands of lines in them and slurping them into memory is a waste. "while (<$fh>)" only reads one line at a time, whereas "for (<$fh>)" reads the entire contents of the file into a temporary array.
2020-01-12www: discard multipart parent on iteration
We're often iterating through messages while writing to another buffer in our WWW interface, causing memory usage to multiply. Since we know we won't need to keep the MIME object around in some cases, and can tell msg_iter to clobber the on-stack variable while it operates on subparts of multipart messages. With xt/mem-msgview.t switched to multipart from the previous commit, this shows a 13 MB memory reduction on that test.
2020-01-11make Filesys::Notify::Simple optional
It's only used by us in public-inbox-watch, and maybe not for long. It's in most installations because Plack pulls it in though, but Plack is no longer required.
2020-01-11doc: technical/ds.txt: describe PublicInbox::DS divergences
Danga::Socket 1.62 was released a few months back and the maintainer indicated it would be the last release. We've diverged significantly in incompatible ways... While most of this should've already been documented in commit messages, putting it all into one document could make it easier-to-digest. It's also a strange design for anybody used to conventional event loops. Maybe this is an unconventional project :P
2020-01-11spawn (and thus popen_rd) die on failure
Most spawn and popen_rd callers die on failure to spawn, anyways, and some are missing checks entirely. This saves us a bunch of verbose error-checking code in callers. This also makes popen_rd more consistent, since it already dies on pipe creation failures.
2020-01-11git: remove ->commit_title method
We haven't used it in SolverGit, yet, and I'll be reworking it to work with ->cat_async, instead.
2020-01-11git: ->modified uses cat_async
While v1 inboxes are typically only a single branch, coderepos will have many branches and being able to pipeline requests to "git cat-file --batch" can help us mask seek times.
2020-01-11allow HTTP_HOST to be '0' via defined() checks
'0' is a valid value for HTTP_HOST, and maybe some folks will want to hit that as port 80 where the HTTP client won't send the ":$PORT" suffix.
2020-01-11inbox: use PublicInbox::Git::host_prefix_url for base_url
Better not to duplicate the same logic across different classes. Also, our git wrapper class is a strange place for host_prefix_url, but it needs to be usable for coderepos, so it's there, for now...
2020-01-09qspawn: catch transient errors on pipe, EPOLL_CTL_ADD
popen_rd dies on pipe()/pipe2() failure due to FD exhaustion. EPOLL_CTL_ADD (via PublicInbox::HTTPD::Async->new) may also fail due to memory exhaustion or exceeding the value of /proc/sys/fs/epoll/max_user_watches
2020-01-09http: log response_write errors
Application-supplied callbacks may error out, try to log them so the PSGI app developer can figure out what went wrong.
2020-01-09listener: EPOLL_CTL_ADD errors are non fatal
EPOLL_CTL_ADD may fail with transient ENOMEM or ENOSPC errors, so don't tear down the process when that happens.
2020-01-08nntp: correctly log long response errors
We cannot safely call "fileno(undef)" without bringing down the entire -nntpd process :x. To ensure no logging regression, we now stash the FD for the duration of the long response to ensure the error can be matched to the original command in logs. Fixes: 207b89615a1a0c06 ("nntp: remove cyclic refs from long_response")
2020-01-08daemon: ignore SIGPIPE while running
This is only needed for IO::Poll users, since users with (signalfd || EVFILT_SIGNAL) support run with SIGPIPE (and all other signals) blocked. Fixes: 81a9a43fb858d197 ("daemon: use sigprocmask to block signals at startup")
2020-01-06syscall: modernize away from pre-Perl-5.6 conventions
"use vars" was superseded by "our" in Perl 5.6, and we can "use parent qw(Exporter)" in favor of manipulating @ISA directly (or the bigger "use base ..."); While we're at it, avoid multiple invocations of constant->import by passing a hashref as a "use" parameter.
2020-01-06treewide: "require" + "use" cleanup and docs
There's a bunch of leftover "require" and "use" statements we no longer need and can get rid of, along with some excessive imports via "use". IO::Handle usage isn't always obvious, so add comments describing why a package loads it. Along the same lines, document the tmpdir support as the reason we depend on File::Temp 0.19, even though every Perl 5.10.1+ user has it. While we're at it, favor "use" over "require", since it it gives us extra compile-time checking.
2020-01-06admin: do not lazy-load Inbox or Config packages
No point in lazy-loading these, since they're always loaded anyways and would not have portability problems on systems with minimal dependencies.
2020-01-06altid: use msgmap at compile time
AltId requires Msgmap to work, which requires SQLite. Search also requires SQLite3 (for Over), nowadays, so there's no reason for us to lazy-load Msgmap and SQLite anymore.
2020-01-06view: update POSIX::strftime usage
The POSIX module is always loaded, so import `strftime' into the namespace so we can use it and take advantage of compile-time arg checking. While we're at it, update and reorder caller functions to use prototypes, too.
2020-01-06hval: export prurl and add prototype
This allows to do some compile-time checking and fills in a missing "use" in PublicInbox::NewsWWW, allowing it to be used standalone and independently of PublicInbox::WWW
2020-01-06wwwstatic: use sprintf for Perl <5.22 compatibility
We only declare a Perl 5.10.1+ requirement, and POSIX::lround was not added until 5.21.4 (5.22.0 for stable releases).
2020-01-05view: msg_html: reduce memory use on reused MIDs
In rare cases where Message-IDs get reused, we do not want to hold onto the large Email::MIME objects in memory after showing the first message. So discard each message as soon as we're done using it so we can save memory for the next message. The new and expensive xt/mem-msgview.t test shows a nearly 14MB reduction for two ~7MB messages. run_script() also gets upgraded to make it easier to pass large inputs via IO GLOBs.
2020-01-05search: remove lookup_article
It was no longer used outside of tests, so don't penalize regular users with the extra function. Just inline it for t/search.t.
2020-01-04tests: fix running without SQLite or Xapian
PublicInbox::Search always loads DBD::SQLite, so we can't blindly "use" it in t/xcpdb-reshard.t. We also need to account for that in TestCommon.
2020-01-04viewdiff: do not anchor spaces after filenames in diffstat
Viewing a CSS-less page in a browser which underlines links can show a long line of underscores after diffstats. Not all browsers underline links by default, though.
2020-01-04searchidx: remove_message: pedantic fix for v1
It shouldn't be possible for v1 inboxes to have multiple matches for a given Message-ID, so the sub would only get called once, but strange things could happen in 2112 :>
2020-01-04searchidx: index_text: use Xapian parameter names
Use the parameter names from the Search::Xapian::TermGenerator manpage for our local variables instead of confusing names...