Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
lektor
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
96ed6f8f
Vérifiée
Valider
96ed6f8f
rédigé
Il y a 3 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
DB: first implementation of the database_queue_multi_add_id function
parent
5d36eb91
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!174
Add batched add for IDs
Pipeline
#2452
en échec
Il y a 3 ans
Étape : build
Modifications
2
Pipelines
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
inc/lektor/database.h
+8
-0
8 ajouts, 0 suppression
inc/lektor/database.h
src/database/queue.c
+65
-0
65 ajouts, 0 suppression
src/database/queue.c
avec
73 ajouts
et
0 suppression
inc/lektor/database.h
+
8
−
0
Voir le fichier @
96ed6f8f
...
...
@@ -103,6 +103,14 @@ bool database_queue_shuffle(lkt_db *db);
bool
database_queue_seekid
(
lkt_db
*
db
,
int
id
,
int
*
out_pos
);
bool
database_queue_dump
(
lkt_db
*
db
,
const
char
*
plt_name
);
/* Add multiple IDs at once to the queue. The `int *` is the pointy thing that
* STB returns to you. Be warned that all the queries will be done 10 per 10,
* so if you do an add with 100 items, it will do 10 requests.
* The function returns `true` if the adds where successfull, `false` if any
* error occured.
* TODO: Add a way to manually set the step count. */
bool
database_queue_multi_add_id
(
lkt_db
*
,
size_t
*
ids_stb_list
,
int
priority
);
/* Control the playing state of the queue. */
bool
database_queue_toggle_pause
(
lkt_db
*
db
);
bool
database_queue_play
(
lkt_db
*
db
,
int
pos
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/database/queue.c
+
65
−
0
Voir le fichier @
96ed6f8f
#include
<lektor/common.h>
#include
<lektor/database.h>
#include
<lektor/internal/dbmacro.h>
#include
<lektor/stb/ds.h>
#define sqlite_just_exec(func, query) \
bool func(lkt_db *db) \
...
...
@@ -1089,3 +1090,67 @@ error:
sqlite3_finalize
(
stmt
);
return
ret
;
}
bool
database_queue_multi_add_id
(
lkt_db
*
db
,
size_t
*
ids
,
int
priority
)
{
if
(
ids
==
NULL
)
{
LOG_ERROR
(
"DB"
,
"Can't add a list of IDs to the queue when the list's pointer is NULL"
);
return
false
;
}
if
((
priority
<
1
)
||
(
priority
>
5
))
{
LOG_ERROR
(
"DB"
,
"The priority must be between 1 and 5, here it is %d"
,
priority
);
return
false
;
}
static
const
int
ADD_STEP
=
10
;
/* TODO: Let the user specify that thing */
static
const
char
*
SQL_STMT_TEMPLATE
=
"INSERT INTO queue (kara_id, priority)"
" SELECT kara.id, %d"
/* The priority */
" FROM kara WHERE kara.id IN (%s)"
/* The list of ids, comma-separated */
";"
;
const
size_t
ids_len
=
arrlenu
(
ids
);
size_t
id_index
=
0
;
char
SQL_STMT
[
LKT_MAX_SQLITE_STATEMENT
];
/* The formated query to add things to the queue */
char
IDS_LIST
[
LKT_LINE_MAX
];
/* The thing that will hold the formated comma-separated list of ids */
SQLITE_BEGIN_TRANSATION
(
db
,
error
);
while
(
id_index
<
ids_len
)
{
const
size_t
remaining
=
MAX
(
ids_len
-
id_index
,
ADD_STEP
);
size_t
index_in_id_string
=
0
;
/* We should not enter in here, but it's fine if we do... */
if
(
remaining
==
0
)
{
LOG_WARN
(
"DB"
,
"Don't add any more IDs because none are remaining"
);
break
;
}
for
(
/* Nothing */
;
id_index
<
(
id_index
+
remaining
);
++
id_index
)
{
void
*
const
addr
=
&
(
IDS_LIST
[
index_in_id_string
]);
const
size_t
max_size
=
LKT_LINE_MAX
-
1
-
index_in_id_string
;
const
int
added
=
safe_snprintf
(
addr
,
max_size
,
"%zu,"
,
ids
[
id_index
]);
if
(
added
<=
0
)
{
/* Ouups... */
LOG_FATAL
(
"Failed to concatenate something to the list string, "
"partial state is: %s"
,
IDS_LIST
);
}
index_in_id_string
+=
(
size_t
)
added
;
}
/* Delete the last comma */
IDS_LIST
[
index_in_id_string
-
1
]
=
'\0'
;
safe_snprintf
(
SQL_STMT
,
LKT_MAX_SQLITE_STATEMENT
,
SQL_STMT_TEMPLATE
,
priority
,
IDS_LIST
);
SQLITE_EXEC
(
db
,
SQL_STMT
,
error
);
}
reorder
(
db
,
priority
,
error
);
SQLITE_END_TRANSATION
(
db
,
error
);
return
true
;
error:
SQLITE_DO_ROLLBACK
(
db
);
return
false
;
}
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter