Skip to content

ValueObservation doesn't trigger for fetchCount #954

@steipete

Description

@steipete

What did you do?

I use this code to get data via a value observer:

    public struct Statistics: Equatable {
        public let tweetCount: Int
    }

    /// Return database infos
    public func statisticsPublisher() -> AnyPublisher<Statistics, Error> {
        ValueObservation.tracking { db in
			// If I uncomment this, the observer works.
            // _ = try Tweet.all().fetchAll(db)
            return Statistics(tweetCount: try Tweet.all().fetchCount(db))
        }
        //.removeDuplicates()
        .publisher(in: dbPool).eraseToAnyPublisher()
    }

Is this a known limitation?

When I call print() the difference is:

tracked region: tweet(*)

vs

tracked region: Tweet(lotsOfProperties,text,updatedAt,userId),tweet(*)

What did you expect to happen?

The observer should fire as new rows are added.

What happened instead?

The observer isn't detecting changes.

Environment

GRDB 5.6, iOS 14.5, Xcode 12.5b3, macOS Big Sur 11.3b6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions