swift


Deleting Data from Firebase Periodically


I am working on a social iOS application which allows posting data to Firebase. However, I would like to clear all posts older than 1 hour. A great example is Instagram Story, where images are removed after 24 hours. The approach I was thinking about included submitting startTime and endTime timestamps and deleting the data client-side, after the endTime has passed the current time. On the other hand, that would require 24/7 users' activity, as users' data would never be deleted if they don't open the application frequently. I believe I would need a server to handle this problem.
I would kindly ask you for suggestions and assistance on how to implement this server-side - as I believe it is the only possible way.
Solution 1 - Cloud Functions
Login to firebase and then select your app, you will now be on the App Overview page. Select the Cloud Function Item. This will allow you to execute some javaScript based on a trigger, there are many different types of triggers such as database triggers or authentication triggers. In this case, you want the trigger to be based on time.
That is this one:
Firebase explains cloud functions better than I can below:
After you write and deploy a function, Google’s servers begin to manage the function immediately, listening for events and running the function when it is triggered. As the load increases or decreases, Google responds by rapidly scaling the number of virtual server instances needed to run your function.
Lifecycle of a function
The developer writes code for a new function, selecting an event provider (such as Realtime Database), and defining the conditions under which the function should execute.
The developer deploys the function, and Firebase connects it to the selected event provider.
When the event provider generates an event that matches the function's conditions, the code is invoked.
If the function is busy handling many events, Google creates more instances to handle work faster. If the function is idle, instances are cleaned up.
When the developer updates the function by deploying updated code, all instances for the old version are cleaned up and replaced by new instances.
When a developer deletes the function, all instances are cleaned up, and the connection between the function and the event provider is removed.
source: https://firebase.google.com/docs/functions/
Solution 2 - Server + Cron Jobs (my preference)
Purchase a cheap server on a monthly subscription (don't need anything fancy should be a few dollars a month), will struggle to find a free one that allows Cron jobs though.
write a script that connects to the firebase database and deletes all the posts older than an hour.
on your server dashboard/control panel create a new Cron Job scheduled to run every hour and point it to the script you just wrote.

Related Links

Swift shorthand null check
Popup window in OS X App
“Fade in and out” animation does not work
Swift 3 : How to create instance of underlying type from Any
Enumerate class members in Swift
Swift: flatMap to Dictionary
Move PHAsset from one Album to Another (Swift)
Non-self delegate is not called
Firebase and reading nested data using Swift
Wrong drag and drop location NSTableView
Swift two delegate function for textfield
Swift linker error in release build fixable by adding code
UITableView row won't removed after being deleted
Simulate Single/Double Tap Swift
How to have a sprite follow another “within bounds”
Azure notifications hub can't register template with content-available

Categories

HOME
tensorflow
numpy
sed
wmic
raspbian
angular2-routing
reportportal
apollo
jscript
recyclerview
jpanel
urlencode
spring-cloud-contract
data-science-experience
shipping
qt-installer
ssms-2016
zoomcharts
quartus
chocolatey
cvs2svn
rails-activerecord
scalaz7
avplayeritem
tfs2013
iis-10
shopping-cart
emv
upnp
vcard
edge-detection
solidworks
hana-studio
fileinfo
multichoiceitems
superagent
invoke-command
piecewise
polymorphism
shapes
google-drive-realtime-api
ios-ui-automation
google-guava-cache
coreclr
deepstream.io
agent
stdclass
constants
upsert
ttcn
worker
crystal-reports-8.5
ruby-on-rails-2
shinyjs
rsqlite
cfeclipse
glkit
chessboard.js
galleriffic
vst
update-site
listadapter
project-online
mpeg-4
approval-tests
direct3d12
hyperthreading
response-headers
isml
hiera
cpan
candidate-key
and-operator
cg
csplit
proxies
valence
colt
zipalign
circos
baucis
leptonica
windows-update
justgage
apache2.2
mailcore
pascals-triangle
objcmongodb
css-tables
blockingqueue
sunspot-rails
wcf-web-api
viewdidload
galaxy-tab
datamember
django-nose
ruby-debug
symbol-server
idictionary
oggvorbis
castle-validators
data-entry

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App