mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 08:47:46 +00:00
feat: add in multiple job ID collision handling
This commit is contained in:
parent
5debd8f739
commit
50c4dd4b43
@ -23,6 +23,14 @@ class SessionJobDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
||||
fun persistJob(job: Job) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val contentValues = ContentValues(4)
|
||||
val existing = database.get(sessionJobTable, "$jobID = ?", arrayOf(job.id!!)) { cursor ->
|
||||
cursor.count
|
||||
} ?: 0
|
||||
// When adding multiple jobs in rapid succession, timestamps might not be good enough as a unique ID. To
|
||||
// deal with this we keep track of the number of jobs with a given timestamp and that to the end of the
|
||||
// timestamp to make it a unique ID. We can't use a random number because we do still want to keep track
|
||||
// of the order in which the jobs were added.
|
||||
job.id += existing
|
||||
contentValues.put(jobID, job.id)
|
||||
contentValues.put(jobType, job.getFactoryKey())
|
||||
contentValues.put(failureCount, job.failureCount)
|
||||
|
Loading…
x
Reference in New Issue
Block a user