[geany/www.geany.org] ac5d8d: Dump only the last nightly build per target
Enrico Tröger
git-noreply at xxxxx
Sat Jul 13 14:19:13 UTC 2019
Branch: refs/heads/master
Author: Enrico Tröger <enrico.troeger at uvena.de>
Committer: Enrico Tröger <enrico.troeger at uvena.de>
Date: Sat, 13 Jul 2019 14:19:13 UTC
Commit: ac5d8dc1b5cfc55bc394f776fb28ac25977d73f0
https://github.com/geany/www.geany.org/commit/ac5d8dc1b5cfc55bc394f776fb28ac25977d73f0
Log Message:
-----------
Dump only the last nightly build per target
When dumping the nightly build database limit the dump to the last
build per target. The previous attempt of dumping the builds of the
last seven days could lead to corrupt references between
builds and targets.
Also fix unintended nested level in the combined JSON dump.
Modified Paths:
--------------
geany/management/commands/dump_database.py
Modified: geany/management/commands/dump_database.py
15 lines changed, 7 insertions(+), 8 deletions(-)
===================================================================
@@ -12,13 +12,12 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from datetime import timedelta
from json import dump, load
from os import unlink
from django.contrib.auth.hashers import make_password
from django.core.management import BaseCommand, call_command
-from django.utils import timezone
+from django.db.models import F
from nightlybuilds.models import NightlyBuild
@@ -88,12 +87,12 @@ def _remove_sensitive_information_from_dump(self):
# ----------------------------------------------------------------------
def _dump_nightly_builds_database(self):
- # dump nightly builds database but limit the data to the last week
- # to reduce dump size
- now_a_week_ago = timezone.now() - timedelta(days=7)
+ # query the last nightly build for each build target for the dump
+ # (dumping all builds would be too large)
queryset = NightlyBuild.objects.\
- filter(build_date__gte=now_a_week_ago).\
- only('nightly_build_id')
+ prefetch_related('nightly_build_target').\
+ filter(nightly_build_target__last_nightly_build_id=F('nightly_build_id')).\
+ order_by('nightly_build_target__project', 'nightly_build_target__identifier')
pks = [str(item.nightly_build_id) for item in queryset]
database_nightlybuilds_filename = 'tmp_database_nightlybuilds.json'
@@ -122,7 +121,7 @@ def _dump_nightly_builds_database(self):
for filename in filenames:
with open(filename) as infile:
data = load(infile)
- records.append(data)
+ records.extend(data)
dump(records, output, indent=2)
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list