archweb
archweb copied to clipboard
Remove old flagrequest when manually unflagging
When manually unflagging the old flagrequest is not removed while it should be.
Number of flag requests can be obtained by:
>>> from packages.models import FlagRequest
>>> FlagRequest.objects.count()
Steps:
- Check the number of flagged packages
- Flag a package
- Unflag the same package
- Number of flagged packages should be the same.
Queries for removing old flagrequests in postgresql
Listing old flagrequests
SELECT fr.id,fr.created,fr.pkgbase,fr.pkgver,fr.pkgrel,fr.epoch FROM packages_flagrequest as fr INNER JOIN packages as ps ON (fr.pkgbase = ps.pkgbase AND fr.pkgver != ps.pkgver AND fr.repo_id = ps.repo_id) ORDER BY fr.created desc;
Deleting old flagrequests
DELETE FROM packages_flagrequest as fr USING packages as ps WHERE fr.pkgbase = ps.pkgbase AND fr.pkgver != ps.pkgver AND fr.repo_id = ps.repo_id;
Missing are the packages of with the pkgbase does not exists anymore in the repos.
Remove packages. This isn't handled by our code yet.
select id,pkgbase from packages_flagrequest as fr where not exists (select * from packages where fr.pkgbase = packages.pkgbase)
Correct query to fetch to be removed packages.
select fr.id, fr.pkgbase, fr.created, fr.pkgver from packages_flagrequest fr left outer join packages p on p.pkgbase = fr.pkgbase and p.repo_id = fr.repo_id and p.flag_date is not null where p.pkgbase is null;
One case, unflag for $pkg can be simply fixed by the following code in def unflag(req, ...):
FlagRequest.objects.filter(pkgbase=pkg.pkgbase,
repo__name__iexact=repo,
pkgver=pkg.pkgver,
epoch=pkg.epoch).delete()
But it will also remove a FlagRequest when it's a split package which should not be done. So the code still has to check if it's a split package and only remove it when it's the last split package left.
Also it seems that [testing] => [core] moves are not handled and aren't removed as well.
Commit https://github.com/archlinux/archweb/commit/7d162a095333b0e2c31a96940e5915848caf4d5c should handle deletions of packages.