OpenRA / OpenRA-Resources

The OpenRA Resource Center helps the community sharing their custom maps.
http://resource.openra.net
Other
21 stars 18 forks source link

Update map report count when report is canceled #307

Closed netnazgul closed 6 years ago

netnazgul commented 6 years ago

Supposedly fixes #306

If it works, existing maps with incorrect non-zero "amount_reports" attribute need to be updated manually in the database.

netnazgul commented 6 years ago

another issue this pr fixes is that maps that were reported >2 times will have big red "ATTENTION" banner even if they don't have active reports. amount_reports is used in html checks whereas in python code Reports container is polled like this: https://github.com/OpenRA/OpenRA-Resources/blob/6f601d98ad0fe5c3adfc98d14a420db50dbaa5b8/openra/api.py#L237-L238

dsimmons87 commented 6 years ago

I was able to reproduce the original problem, and this fix works fine for me.

I guess ideally the hard coded amount_reports variable shouldn't exist, and a proper relationship should be set up between Maps and Reports, but that would involve a lot more changes, and this fixes the problem (other than updating the database).

dsimmons87 commented 6 years ago

Also with regards to updating existing records, does this SQL look ok:

UPDATE openra_maps
SET amount_reports = (
    SELECT COUNT(*) FROM openra_reports WHERE ex_id = openra_maps.id
);

I tested it on my local version and it updated correctly there, but I thought I should post it here too to check in case there is something I've missed.

dsimmons87 commented 6 years ago

Ok, this has now been deployed and the SQL above run.