Giter VIP home page Giter VIP logo

Comments (7)

marcin-bo avatar marcin-bo commented on September 15, 2024

Actually we should not delete self?.resolveRelationships() in SynchronizationManager.update() to keep client's synchronization working:

// 
// file: SynchronizationManager.swift
// 

// define new function that handles resolving relationships
public func lateResolveRelationships() {
      persistentStore.performAndWait { [weak self] in
            self?.resolveRelationships()
            self?.save()
      }
}
//
// file: SynchronizationManager+SeedDB.swift
//

// ...
public func seedDBFromJSONFiles(in directory: String, in bundle: Bundle) throws {
      // ...
      self.lateResolveRelationships() // in last line call new function after data from all JSONs is seeded
}

from contentful-persistence.swift.

loudmouth avatar loudmouth commented on September 15, 2024

Hey @marcin-bo thanks for the report.

It sounds like there are two separate issues here:

Issue 1: Bug with link resolution for multiple page syncs.

I'm surprised to hear this isn't working as I have tests. These tests use the following two stubs which are the separate pages: 1 and 2 for resolving relationships that have parents in one page and children in another—regardless of which is on which page.

Each new SyncSpace that is sent to this persistence lib from the core SDK contains the latest delta changes which come on each page. The persistence lib then iterates over all entries (new and old) and resolves links to all other entries and assets... At least this is how this library is supposed to work. If your convinced there is a bug here, maybe you could help me and open a support request at support.contentful.com and tell the support folks that the iOS SDK dev sent you there and link this Github issue. The reason i suggest opening a ticket is that your specific content and content model may highlight an edge case that is being overlooked.

Issue 2: Non-optimized link resolution when seeding from database.

The abovementioned implementation was meant to handle all cases when hitting the API, but when seeding from bundled content, I think you're right that it makes sense to resolve the relationships after all pages have been deserialized rather than between each page.

Anyway, I I won't be able to get to this until Monday at least.

from contentful-persistence.swift.

marcin-bo avatar marcin-bo commented on September 15, 2024

Hi @loudmouth

I think that in my case it's issue 2. When I sync database with Contentful API relationships are resolved correctly. When I seed database some relatioships are missing.

from contentful-persistence.swift.

loudmouth avatar loudmouth commented on September 15, 2024

Hey @marcin-bo sorry I hadn't gotten to this yet. I had quite a bit of work to go through yesterday an today. Rest assured I'll address it this week. In the meantime, use your fork if that's working for you ;-)

from contentful-persistence.swift.

loudmouth avatar loudmouth commented on September 15, 2024

@marcin-bo I found the real culprit here: SyncSpace has a method updateWithDiffs(from syncSpace: SyncSpace that needs to be called to merge instances in memory before they are sent to this library to have their data persisted.

I will need to merge a PR on the main contentful.swift repo to make that method public and then replace the `self.update(with: syncSpace) call in this lib with the folling:

let newestSyncSpace = try jsonDecoder.decode(SyncSpace.self, from: data)
syncSpace.updateWithDiffs(from: newestSyncSpace)

With that change, relationship resolution only needs to happen once, after all the files have been loaded in memory, i.e. outside of the while loop. This will also make the behavior consistent with doing api requests during runtime and then persisting the data to disk with this lib.

Stay tuned for a fix.

from contentful-persistence.swift.

loudmouth avatar loudmouth commented on September 15, 2024

Actually, rather than merging all sync spaces in memory (who knows what kind of memory ballooning a large space could cause), i have found a way to manually keep track of the relationship metadata that the persistence lib uses to resolve relationships. The relationshipsToResolve property now keeps track of which relationships have already been resolved.

from contentful-persistence.swift.

loudmouth avatar loudmouth commented on September 15, 2024

@marcin-bo 0.9.1 is now available on Cocoapods and via Carthage or SPM.

from contentful-persistence.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.