Skip to content

Commit

Permalink
[GNIP #3944] Make GeoFence efficient for GeoNode instances with a lar…
Browse files Browse the repository at this point in the history
…ge number of layers
  • Loading branch information
afabiani committed Apr 3, 2019
1 parent f7cfb5f commit b9430e8
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions geonode/geoserver/management/commands/sync_geonode_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#
#########################################################################

import json
import ast
import sys
import json

from django.core.management.base import BaseCommand

Expand All @@ -28,7 +29,7 @@
from geonode.geoserver.helpers import set_attributes_from_geoserver


def sync_geonode_layers(ignore_errors, filter, username, updatepermissions=None, updatethumbnails=None):
def sync_geonode_layers(ignore_errors, filter, username, updatepermissions, updatethumbnails):
layers = Layer.objects.all().order_by('name')
if filter:
layers = layers.filter(name__icontains=filter)
Expand All @@ -41,15 +42,15 @@ def sync_geonode_layers(ignore_errors, filter, username, updatepermissions=None,
try:
count += 1
print 'Syncing layer %s/%s: %s' % (count, layers_count, layer.name)
if updatepermissions or not updatethumbnails:
if ast.literal_eval(updatepermissions):
print 'Syncing permissions...'
# sync permissions in GeoFence
perm_spec = json.loads(_perms_info_json(layer))
# re-sync GeoFence security rules
layer.set_permissions(perm_spec)
# recalculate the layer statistics
set_attributes_from_geoserver(layer, overwrite=True)
if updatethumbnails or not updatepermissions:
if ast.literal_eval(updatethumbnails):
print 'Regenerating thumbnails...'
layer.save()
except Exception:
Expand Down Expand Up @@ -91,18 +92,14 @@ def add_arguments(self, parser):
default=None,
help="Only update data owned by the specified username")
parser.add_argument(
'-p',
'--updatepermissions',
action='store_true',
dest="updatepermissions",
default=False,
default='True',
help="Update only the layer permissions. Does not regenerate styles and thumbnails")
parser.add_argument(
'-t',
'--updatethumbnails',
action='store_true',
dest="updatethumbnails",
default=False,
default='True',
help="Update only the layer styles and thumbnails. Does not re-sync security rules.")

def handle(self, **options):
Expand Down

0 comments on commit b9430e8

Please sign in to comment.