Optimise reading in of meta from files

This commit is contained in:
Dan Hawkins 2021-12-21 18:21:37 +00:00
commit f21873bfce

View file

@ -600,6 +600,7 @@ class MetaInfo extends GISJsonSerialised {
interface IRelatedMetaInfo {
abstract void deserialiseJson(rawmeta)
abstract LinkedHashMap serialisationdata()
abstract String getuniqueid()
}
abstract class RelatedMetaInfo extends GISJsonSerialised implements IRelatedMetaInfo {
@ -612,20 +613,24 @@ class MetaInfo extends GISJsonSerialised {
abstract void deserialiseJson(rawmeta)
abstract LinkedHashMap serialisationdata()
abstract String getuniqueid()
}
class RelatedMetaInfo_v0_1 extends RelatedMetaInfo {
private MetaInfo meta
private String offsetpath
private String uniqueid
RelatedMetaInfo_v0_1(script, offsetpath = '', MetaInfo meta = null) {
RelatedMetaInfo_v0_1(script, String offsetpath = '', MetaInfo meta = null, String uniqueid = UUID.randomUUID().toString()) {
super(script, '0.1')
this.offsetpath = offsetpath
this.uniqueid = uniqueid
this.meta = meta
}
void deserialiseJson(rawmeta) {
offsetpath = rawmeta['offsetpath']
uniqueid = rawmata['uniqueid'] ?: uniqueid
meta = new MetaInfo(script)
meta.deserialiseJson(rawmeta['meta'])
}
@ -634,34 +639,47 @@ class MetaInfo extends GISJsonSerialised {
def data = [
'format' : format,
'offsetpath' : offsetpath,
'uniqueid' : uniqueid,
'meta' : meta.serialisationdata(),
]
return data
}
String getuniqueid() {
return uniqueid;
}
}
class RelatedMetaInfo_v0_2 extends RelatedMetaInfo {
private String importpath
private String offsetpath
private String uniqueid
RelatedMetaInfo_v0_2(script, importpath = '', offsetpath = '') {
RelatedMetaInfo_v0_2(script, String importpath = '', String offsetpath = '', String uniqueid = UUID.randomUUID().toString()) {
super(script, '0.2')
this.importpath = importpath
this.offsetpath = offsetpath
this.uniqueid = uniqueid
}
void deserialiseJson(rawmeta) {
//format = rawmeta['format']
offsetpath = rawmeta['offsetpath']
uniqueid = rawmata['uniqueid']
}
LinkedHashMap serialisationdata() {
def data = [
'format' : format,
'offsetpath' : offsetpath,
'uniqueid' : uniqueid
]
return data
}
String getuniqueid() {
return uniqueid;
}
}
private ProductInfo productinfo
@ -831,7 +849,7 @@ class MetaInfo extends GISJsonSerialised {
script.echo("Deserialising meta at file: ${importedmetafile} (destpath: ${destpath})")
mi.deserialiseJson(importedmetafile)
RelatedMetaInfo rmi = new RelatedMetaInfo_v0_2(script, importedmetafile, adjustedpath)
RelatedMetaInfo rmi = new RelatedMetaInfo_v0_2(script, importedmetafile, adjustedpath, mi.productinfo.uniqueid)
if (appendtoparentmeta) {
associatedmeta.add(rmi)
}
@ -956,6 +974,13 @@ class MetaInfo extends GISJsonSerialised {
String show() {
return "Iteration:\nLevel: ${level}\nGathered path: ${gatheredpath}\nGathered meta path: ${gatheredmetapath}\nLimited depth: ${limiteddepth}\nMax depth: ${maxdepth}"
}
void add(CollectedMeta item) {
metacollection.add(item)
metamap.put(item.metainfo.productinfo.uniqueid, item)
}
CollectedMeta
}
def openchildmeta(IterationInfo ii, RelatedMetaInfo relatedmetainfo) {
@ -965,7 +990,11 @@ class MetaInfo extends GISJsonSerialised {
def String nextgatheredmetapath = (ii.gatheredmetapath == '' ? "${relatedmetainfo.offsetpath}/${METAFOLDERNAME}" : "${ii.gatheredmetapath}/${relatedmetainfo.offsetpath}")
def importedmetafile = "${nextgatheredmetapath}/${METAFILENAME}"
def boolean imported
if (script.fileExists(importedmetafile)) {
// If this has already been read in from a file
if (relatedmetainfo.uniqueid() in ii.metamap) {
mi = metamap[relatedmetainfo.uniqueid()].metainfo
imported = true
} else if (script.fileExists(importedmetafile)) {
mi.deserialiseJson(importedmetafile)
imported = true
} else {
@ -985,7 +1014,7 @@ class MetaInfo extends GISJsonSerialised {
def walkrelated_v0_1(IterationInfo ii) {
script.echo("Walk related v0.1: ${ii.show()}")
if (!ii.limiteddepth || ii.maxdepth > 0) {
ii.metacollection.add(new CollectedMeta(this, ii.gatheredpath, ii.gatheredmetapath))
ii.add(new CollectedMeta(this, ii.gatheredpath, ii.gatheredmetapath))
ii.comment += "${ii.level} ".padRight(ii.level * 4) + globalreleasetag() + '\n'
for (relatedmetainfo in associatedmeta) {
if (!relatedmetainfo.format || relatedmetainfo.format == '0.1') {
@ -1015,7 +1044,7 @@ class MetaInfo extends GISJsonSerialised {
def walkrelated(IterationInfo ii) {
script.echo("Walk related: ${ii.show()}")
if (!ii.limiteddepth || ii.maxdepth > 0) {
ii.metacollection.add(new CollectedMeta(this, ii.gatheredpath, ii.gatheredmetapath))
ii.add(new CollectedMeta(this, ii.gatheredpath, ii.gatheredmetapath))
ii.comment += "${ii.level} ".padRight(ii.level * 4) + globalreleasetag() + '\n'
for (relatedmetainfo in associatedmeta) {
script.echo("Related meta info: ${relatedmetainfo.offsetpath} format: ${relatedmetainfo.format}")