forked from MapComplete/MapComplete
Feature: stabilize saved history, add code to cleanup old preferences, make loading preferences faster (which prevents a 'hang') when just logged in
This commit is contained in:
parent
dc1e582664
commit
c1d3f35d30
10 changed files with 249 additions and 146 deletions
|
@ -113,11 +113,11 @@ export class ChangesetHandler {
|
|||
|
||||
private async UploadWithNew(
|
||||
generateChangeXML: (csid: number, remappings: Map<string, string>) => string,
|
||||
openChangeset: UIEventSource<number>,
|
||||
openChangeset: UIEventSource<{ id: number, opened: number }>,
|
||||
extraMetaTags: ChangesetTag[]
|
||||
) {
|
||||
const csId = await this.OpenChangeset(extraMetaTags)
|
||||
openChangeset.setData(csId)
|
||||
openChangeset.setData({ id: csId, opened: new Date().getTime() })
|
||||
const changeset = generateChangeXML(csId, this._remappings)
|
||||
console.log(
|
||||
"Opened a new changeset (openChangeset.data is undefined):",
|
||||
|
@ -145,7 +145,7 @@ export class ChangesetHandler {
|
|||
public async UploadChangeset(
|
||||
generateChangeXML: (csid: number, remappings: Map<string, string>) => string,
|
||||
extraMetaTags: ChangesetTag[],
|
||||
openChangeset: UIEventSource<number>
|
||||
openChangeset: UIEventSource<{ id: number, opened: number }>
|
||||
): Promise<void> {
|
||||
if (
|
||||
!extraMetaTags.some((tag) => tag.key === "comment") ||
|
||||
|
@ -169,18 +169,21 @@ export class ChangesetHandler {
|
|||
}
|
||||
|
||||
console.log("Trying to reuse changeset", openChangeset.data)
|
||||
if (openChangeset.data) {
|
||||
const now = new Date()
|
||||
const changesetIsUsable = openChangeset.data !== undefined &&
|
||||
(now.getTime() - openChangeset.data.opened < 24 * 60 * 60 * 1000)
|
||||
if (changesetIsUsable) {
|
||||
try {
|
||||
const csId = openChangeset.data
|
||||
const oldChangesetMeta = await this.GetChangesetMeta(csId)
|
||||
const oldChangesetMeta = await this.GetChangesetMeta(csId.id)
|
||||
console.log("Got metadata:", oldChangesetMeta, "isopen", oldChangesetMeta?.open)
|
||||
if (oldChangesetMeta.open) {
|
||||
// We can hopefully reuse the changeset
|
||||
|
||||
try {
|
||||
const rewritings = await this.UploadChange(
|
||||
csId,
|
||||
generateChangeXML(csId, this._remappings)
|
||||
csId.id,
|
||||
generateChangeXML(csId.id, this._remappings)
|
||||
)
|
||||
|
||||
const rewrittenTags = this.RewriteTagsOf(
|
||||
|
@ -188,7 +191,7 @@ export class ChangesetHandler {
|
|||
rewritings,
|
||||
oldChangesetMeta
|
||||
)
|
||||
await this.UpdateTags(csId, rewrittenTags)
|
||||
await this.UpdateTags(csId.id, rewrittenTags)
|
||||
return // We are done!
|
||||
} catch (e) {
|
||||
this._reportError(e, "While reusing a changeset " + openChangeset.data)
|
||||
|
@ -236,9 +239,9 @@ export class ChangesetHandler {
|
|||
/**
|
||||
* Given an existing changeset with metadata and extraMetaTags to add, will fuse them to a new set of metatags
|
||||
* Does not yet send data
|
||||
* @param extraMetaTags: new changeset tags to add/fuse with this changeset
|
||||
* @param rewriteIds: the mapping of ids
|
||||
* @param oldChangesetMeta: the metadata-object of the already existing changeset
|
||||
* @param extraMetaTags new changeset tags to add/fuse with this changeset
|
||||
* @param rewriteIds the mapping of ids
|
||||
* @param oldChangesetMeta the metadata-object of the already existing changeset
|
||||
*
|
||||
* @public for testing purposes
|
||||
*/
|
||||
|
@ -250,7 +253,7 @@ export class ChangesetHandler {
|
|||
id: number
|
||||
uid: number // User ID
|
||||
changes_count: number
|
||||
tags: any
|
||||
tags: Record<string, string>
|
||||
}
|
||||
): ChangesetTag[] {
|
||||
// Note: extraMetaTags is where all the tags are collected into
|
||||
|
@ -300,11 +303,11 @@ export class ChangesetHandler {
|
|||
|
||||
/**
|
||||
* Updates the id in the AllElements store, returns the new ID
|
||||
* @param node: the XML-element, e.g. <node old_id="-1" new_id="9650458521" new_version="1"/>
|
||||
* @param node the XML-element, e.g. <node old_id="-1" new_id="9650458521" new_version="1"/>
|
||||
* @param type
|
||||
* @private
|
||||
*/
|
||||
private static parseIdRewrite(node: any, type: string): [string, string] {
|
||||
private static parseIdRewrite(node: any, type: "node" | "way" | "relation"): [string, string] {
|
||||
const oldId = parseInt(node.attributes.old_id.value)
|
||||
if (node.attributes.new_id === undefined) {
|
||||
return [type + "/" + oldId, undefined]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue