I have a realm database used in my xamarin android and iOS application. I have an API which feeds data to my app in a paginated manner. Whenever returns data the same is added to the DB from a ViewModel, which is common for both Android and iOS. Afterward, a broadcast is sent to update the screen. On receiving the broadcast I am trying to fetch the new set of data from the database. Let's say initially I don't have any data and on receiving the first broadcast I will fetch all the items, say 10 items, on receiving the next broadcast how can I fetch all the items except the first 10 items, and so on. ie selecting data from table in such a way that in each query the start index or row number changes.
Related
I'm currently building a Twitter clone that needs the following features:
Infinite scrolling.
Show button when new tweets are available. Fetch new tweets when clicking on this button.
Regularly update reply, retweet and like count of fetched tweets.
I'm using relay pagination on my backend and fetchMore with the endCursor that is returned by a query of all tweets (first 5) on my frontend to allow infinite scrolling.
To detect if new tweets are available, I can use a subscription.
The problem is that when a new tweet is available and I poll or refetch the counters and new tweets, the already fetched items are falling off the page, or the already fetched pages should be fetched again. How to solve this?
I was expecting that the already fetched tweets were merged with the new tweets.
Kotlin Flow has a function distinctUntilChanged(old, new -> Boolean) which can be used with Android Room database to compare the table rows before and after a write operation (source code).
Is there any way to access old and new parameter objects outside of the distinctUntilChanged block?
Background: I want to check whether a record has been added or deleted from my room database by comparing size of old and new in a flow onEach{} block and action based on result.
I have a Google Spreadsheet with multiple sheets. We paste a table of data into sheet1 and all the other sheets have filters based basically on the 'membernumber' value in one of the columns (so that the mass data that gets imported gets sorted by our individual members). We then want to send an email with an updated table for each individual member (so therefore my script will access each individual sheet and copy the filtered table of data to the email message body).
But my question is for one of the early parts of this script: How can I make my Apps Script automatically refresh the filters in all of our sheets after we've imported the new data in sheet1? Right now we go manually and click the filter icon and re-select the member's number, or 0 if they don't have data for that day. It's killing me.
I know apps script doesn't have an AutoFilter method, but maybe with the Sheet API I can refresh them? I think this may be the method I need to call.
Let's say I have a sheet, would I just write:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("example");
sheet.updateFilterView({"fields": *}); //since I want to update all filters, all fields on each sheet
I really wish the Google sheets API had some examples!
I am building a website that will notify users of certain changes to their account via a notification bar at the top of the screen (similar to the way SO notifies of new badges).
In my DB I have a table that list the events and also a flag to denote whether they have been notified of the change yet or not. The table is of the form :
UserID AccountEvent EventDescription HasBeenNotified
ABC123 1 Your price deal ends in 2 weeks FALSE
What I would like to achieve is:
Customer logs in and is shown notification (assuming one needs to
happen)
Customer clicks to acknowledge message
DB HasBeenNotified field set to TRUE (to acknowledge notification has occurred)
I have been able to achieve all this but there is a snag!
I am putting the events that need to be notified into the HttpRuntime.Cache with a 10 min expiry so I don't need to keep polling the DB.
The issue this creates for me is that a customer could potentially see multiple notifications of the same message until the cache expires, for example:
Customer logs in and app logic looks in cache and says customer ABC123 needs to be
notified of X
Customer then acknowledges message (which updates DB to set notification flag to TRUE)
Cache does not yet reflect updated DB so if customer navigates to new page the same notification message is fired (until cache expires)
As far as I know I cannot update the actual data within the Cache (can only Remove data from cache based on cache key).
Can anybody provide hints and tips of how to get around the issue of multiple notifications?
Why not burst the cache? Remove that key from the cache?
Or you can update the cache by setting it again to new HasBeenNotified value or even set it to null which you should deal with and accept as empty.
HttpRuntime.Cache["YourKey"] = "";//new object/value;
I have a Cocoa Mac application with a search field and a collection view bound to an sqlite table through CoreData. The table contains several hundred thousand records with text fields (name, place, ...) indexed by name. I'm using BEGINSWITH predicate in a search field binding to select a dozen of records for display in a collection view. Everything works fine, but the problem is that CoreData loads the whole table into memory at the first query request and only then does the necessary filtering of records for display which means considerable delay for the user.
Is there a way to set up CoreData so that the whole table does not load into memory? Ideally, I would like to fetch only the first 100 items from a range of alphabetically sorted records for every query in the search field.
On iOS, this would be achieved using a NSFetchedResultsController. The following question describes the Mac equivalent controllers (such as NSArrayController): NSFetchedResultsController Mac OSX Cocoa equivalent.
EDIT
As per my comment below, a NSFetchRequest should be created in conjunction with the array controller. This can then be configured with fetchLimit and fetchOffset to determine how many fetch results are returned.
Make sure that you have the fetch request set to fetch as faults only. That way only the objects whose attributes who are actively accessed will be fully loaded into memory.