zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: [PATCH 1/1] Squashed commit of the following:
Date: Sat, 02 Jun 2018 00:45:17 +0200	[thread overview]
Message-ID: <31972.1527893117@thecus> (raw)
In-Reply-To: <20180601133048.m7crvdzodzntxcsq@NUC.doronbehar.com>

Doron Behar wrote:
> However, the bad news is that I'm afraid that calling `luarocks config`
> twice like that whenever I query the cache validity, is a huge
> performance hit.

> The solution which will most likely best solve this issue is to use a
> similar cache mechanism for these values as well. This *inner* cache's

Sounds rather complicated but perhaps necessary depending on just how
slow it is. A global variable – typically named _cache_… – is one
option for caching that avoids much of the complexity of the disk cache
mechanism if the lifetime of the session is an appropriate policy for
how long to retain the cached information.

> I'd be glad to get some feedback, thanks!


> 	(( $+functions[___luarocks_manually_store_cache_configs_paths] )) ||
> 	___luarocks_manually_store_cache_configs_paths(){
> 	  user_config_path="$(_call_program user_config_path luarocks config --user-config)"
> 	  system_config_path="$(_call_program system_config_path luarocks config --system-config)"

These variables should be declared local. If the intention is for them
to be global, use typeset -g and prefix the names with something like
_cache_luarocks_.

> 	  print user_config_path=$user_config_path > ${cache_dir}/luarocks_configs_paths
> 	  print system_config_path=$system_config_path >> ${cache_dir}/luarocks_configs_paths

You might need to quote the values with ${(qq)user_config_path} in case
they have spaces in their values. By using braces around the print
statements only one redirection will be needed instead of the
redirection and append: { print ...; print ... } > cache

> 	  local where_luarocks=$(where luarocks)

Use $commands[luarocks] rather than where in a command substitution.
Command substitution typically requires a forked subshell which will be
less efficient.

> 	  # luarocks_configured_values
> 	  local configured_lua_version configured_user_tree configured_system_tree
> 	  # luarocks_configs_paths
> 	  local config
> 	  if [[ -e ${cache_dir}/luarocks_configs_paths ]]; then
> 	    if [ ${where_luarocks} -nt ${cache_dir}/luarocks_configs_paths ]; then

It is generally better to use [[ ... ]] for all conditions unless you're
writing a script targeted at /bin/sh – which is not the case here.

> 	  if [[ -f ${user_manifest_file} ]] || [[ -f ${system_manifest_file} ]]; then
> 	    if [[ -f ${cache_file} ]]; then
> 	      # if either one of the manifest files is newer then the cache:
> 	      if [ ${user_manifest_file} -nt ${cache_file} ] || [ ${system_manifest_file} -nt ${cache_file} ]; then
> 	        (( 1 ))
> 	      else
> 	        (( 0 ))
> 	      fi
> 	    else
> 	      (( 1 ))
> 	    fi
> 	  else
> 	    (( 1 ))
> 	  fi

I find this (( 1 )) stuff confusing. If I'm not mistaken the whole thing
is equivalent to:

  [[ ( ! -f ${user_manifest_file} && ! -f ${system_manifest_file} ) ||
      ! -f ${cache_file} || ${user_manifest_file} -nt ${cache_file} ||
      ${system_manifest_file} -nt ${cache_file} ]]

As for the logic, I'd mainly question what happens when one but not both
of the manifest files is found to not exist.

Note that && and || can be used inside [[ ... ]].

Oliver


  reply	other threads:[~2018-06-03  0:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-26 16:14 [PATCH 0/1] *** Add luarocks completion *** doron.behar
2018-05-26 16:14 ` [PATCH 1/1] Squashed commit of the following: doron.behar
2018-05-28 10:48   ` Oliver Kiddle
2018-05-29 15:38     ` Doron Behar
2018-05-29 22:00       ` Oliver Kiddle
2018-05-30 12:47         ` Doron Behar
2018-05-30 15:43           ` Oliver Kiddle
2018-06-01  7:18             ` Doron Behar
2018-06-01 13:30               ` Doron Behar
2018-06-01 22:45                 ` Oliver Kiddle [this message]
2018-06-03 21:46                   ` Daniel Shahaf
2018-06-05 15:41                   ` Doron Behar
2018-06-07 15:59                     ` Oliver Kiddle
2018-06-07 16:20                       ` Doron Behar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=31972.1527893117@thecus \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).