[pmg-devel] [PATCH pmg-api 1/2] fix #4392: keep empty user bl/wl in database

Stefan Sterz s.sterz at proxmox.com
Thu Feb 22 11:56:30 CET 2024


On Thu Feb 15, 2024 at 12:58 PM CET, Dominik Csapak wrote:
> since our cluster sync does currently not handle vanishing rows.
> So by keeping the empty entries, they get properly synced to the
> other nodes.
>
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> This should be seen as a workaround for now. The "real" fix would
> probably be to use a better db schema for the user bl/wl. With that
> we have to do a db migration anyway so we can then cleanup the empty
> entries too.
>

this does seem to work as advertised. one small side-effect of keeping
empty entries is that they will still be suggested in the front-ends
combobox.

syncing worked in both direction for me.

>  src/PMG/Quarantine.pm | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/src/PMG/Quarantine.pm b/src/PMG/Quarantine.pm
> index d3d0640..bd231e4 100644
> --- a/src/PMG/Quarantine.pm
> +++ b/src/PMG/Quarantine.pm
> @@ -71,16 +71,15 @@ sub add_to_blackwhite {
>  	}
>
>  	my $queries = "DELETE FROM UserPrefs WHERE pmail = $qu AND (Name = 'WL' OR Name = 'BL');";
> -	if (scalar(keys %{$list->{WL}})) {
> -	    $queries .=
> -	    "INSERT INTO UserPrefs (PMail, Name, Data, MTime) " .
> -	    "VALUES ($qu, 'WL', $wlist, EXTRACT (EPOCH FROM now())::INTEGER);";
> -	}
> -	if (scalar(keys %{$list->{BL}})) {
> -	    $queries .=
> -	    "INSERT INTO UserPrefs (PMail, Name, Data, MTime) " .
> -	    "VALUES ($qu, 'BL', $blist, EXTRACT (EPOCH FROM now())::INTEGER);";
> -	}
> +
> +	$queries .=
> +	"INSERT INTO UserPrefs (PMail, Name, Data, MTime) " .
> +	"VALUES ($qu, 'WL', $wlist, EXTRACT (EPOCH FROM now())::INTEGER);";
> +
> +	$queries .=
> +	"INSERT INTO UserPrefs (PMail, Name, Data, MTime) " .
> +	"VALUES ($qu, 'BL', $blist, EXTRACT (EPOCH FROM now())::INTEGER);";
> +

one small nit (that really isn't this patches fault): imo this should be
wrapped like this:

```
$queries .= "INSERT INTO UserPrefs (PMail, Name, Data, MTime) " .
    "VALUES ($qu, 'WL', $wlist, EXTRACT (EPOCH FROM now())::INTEGER);";

$queries .= "INSERT INTO UserPrefs (PMail, Name, Data, MTime) " .
    "VALUES ($qu, 'BL', $blist, EXTRACT (EPOCH FROM now())::INTEGER);";
```

so consider this:

Tested-by: Stefan Sterz <s.sterz at proxmox.com>

>  	$dbh->do($queries);
>      }
>





More information about the pmg-devel mailing list