Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe to LimitSizeTo does not notify on deletions #320

Closed
bergi9 opened this issue Jan 8, 2020 · 2 comments
Closed

Subscribe to LimitSizeTo does not notify on deletions #320

bergi9 opened this issue Jan 8, 2020 · 2 comments

Comments

@bergi9
Copy link
Contributor

bergi9 commented Jan 8, 2020

Unlike ExpireAfter the LimitSizeTo does not notify the subscribers on deletion, only on completion.

I listen on a Observable and to keep track of it (like history) I put it into a ObservableChangeSet and persist it. Basically a persistable history of an Observable. The Observable I listen runs forever. But the LimitSizeTo never notify the subscriber when deletion occurs only when the ISourceCache completes. So I cannot delete the oldest objects from the database to keep the memory/disk size constant.

The code where it fails for me:

public IObservable<IChangeSet<TObject, TKey>> CreatePersistenceObservableChangeSet<TObject, TKey>(
            IObservable<TObject> fromObservable,
            Func<TObject, TKey> keySelector,
            int sizeLimit = 0)
        {
            return ObservableChangeSet.Create(cache =>
            {
                var collection = GetCollection<TObject>();
                var compositeDisposable = new CompositeDisposable();

                // initial load from database after restart
                cache.AddOrUpdate(collection.FindAll());

                if (sizeLimit > 0)
                {
                    cache.LimitSizeTo(sizeLimit)
                        .Subscribe(items =>
                        {
                            foreach (var keyValuePair in items)
                            {
                                collection.Delete(keyValuePair.Key);
                            }
                        })
                        .DisposeWith(compositeDisposable);
                }

                fromObservable.Subscribe(item =>
                    {
                        collection.Upsert(keySelector(item), item);
                        cache.AddOrUpdate(item);
                    })
                    .DisposeWith(compositeDisposable);

                return compositeDisposable;
            }, keySelector);
        }
@RolandPheasant
Copy link
Collaborator

Sorry for the delay in responding for this.

Would it be possible to produce a failing unit test?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants