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
568d7397
Vérifiée
Valider
568d7397
rédigé
Il y a 4 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
CACHE: Get ride of long and complicated macro
parent
46de53cd
Branches
Branches contenant la validation
Étiquettes
Étiquettes contenant la validation
1 requête de fusion
!157
Caching for karas & refactor & others
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/database/cache.c
+29
-41
29 ajouts, 41 suppressions
src/database/cache.c
avec
29 ajouts
et
41 suppressions
src/database/cache.c
+
29
−
41
Voir le fichier @
568d7397
...
...
@@ -5,15 +5,6 @@
#include
<lektor/internal/dbmacro.h>
#include
<math.h>
/* Cache operations */
#define _get_ 1
#define _set_ 2
/* The 'set' operation are not needed outside of this file, make them private */
#define DEF_PRIVATE(op) DEF_PRIVATE_##op
#define DEF_PRIVATE_2 PRIVATE_FUNCTION
/* Set => private */
#define DEF_PRIVATE_1
/* Get => public */
/* Forward declarations for set operations */
PRIVATE_FUNCTION
bool
database_set_kara_mtime_id
(
volatile
sqlite3
*
,
int
,
uint64_t
);
PRIVATE_FUNCTION
bool
database_set_kara_duration_id
(
volatile
sqlite3
*
,
int
,
uint64_t
);
...
...
@@ -76,40 +67,37 @@ database_cache_kara(volatile sqlite3 *db, int id)
LOG_INFO
(
"CACHE"
,
"Cached mtime %ld and duration %ld for '%s' kara %d"
,
mtime
,
duration_uint
,
filepath
,
id
);
}
#pragma message(TODO "Cache the 'get' with the next `N` karas. Use static __thread variables for that.")
#pragma message(TODO "Add private 'packed' get for cache values")
/* Cache and retry if the kara was not present in the cache */
#define ___cache_and_retry(what, pointer) \
if ((pointer what) == 0 && !retry_once) { \
database_cache_kara(db, id); \
retry_once = true; \
goto retry; \
#define ___cache_set_from_id(what) \
PRIVATE_FUNCTION bool database_set_kara_##what##_id(volatile sqlite3 *db, int id, uint64_t what) \
{ \
bool ret_code = false; \
sqlite3_stmt *stmt = NULL; \
SQLITE_PREPARE(db, stmt, "UPDATE kara SET cached_" #what " = ? WHERE id = ?;", error); \
SQLITE_BIND_INT(db, stmt, 1, what, error); \
SQLITE_BIND_INT(db, stmt, 2, id, error); \
SQLITE_STEP_OK(db, stmt, error); \
ret_code = true; \
error: \
sqlite3_finalize(stmt); \
return ret_code; \
}
/* Define a get/set operation on the cache */
#define ___cache_operation_db_function(op, what, pointer) \
DEF_PRIVATE(op) bool database##op##kara_##what##_id(volatile sqlite3 *db, int id, uint64_t pointer what) \
#define ___cache_get_from_id(what) \
bool database_get_kara_##what##_id(volatile sqlite3 *db, int id, uint64_t *what) \
{ \
/* The 'if true' / 'if false' will be suppressed by the compilator */
\
bool ret_code = false; \
bool retry_once = false; \
sqlite3_stmt *stmt = NULL; \
/* If define a GET operation */
\
if (op == _get_) { \
retry: \
pointer what = 0;
\
*what = 0;
\
SQLITE_PREPARE(db, stmt, "SELECT cached_" #what " FROM kara WHERE id = ?;", error); \
SQLITE_BIND_INT(db, stmt, 1, id, error); \
SQLITE_STEP_ROW(db, stmt, error); \
pointer what = sqlite3_column_int64(stmt, 0); \
___cache_and_retry(what, pointer); \
}
/* If define a SET operation */
\
else if (op == _set_) { \
SQLITE_PREPARE(db, stmt, "UPDATE kara SET cached_" #what " = ? WHERE id = ?;", error); \
SQLITE_BIND_INT(db, stmt, 1, pointer what, error); \
SQLITE_BIND_INT(db, stmt, 2, id, error); \
SQLITE_STEP_OK(db, stmt, error); \
*what = sqlite3_column_int64(stmt, 0); \
if ((*what) == 0 && !retry_once) { \
database_cache_kara(db, id); \
retry_once = true; \
goto retry; \
} \
ret_code = true; \
error: \
...
...
@@ -129,9 +117,9 @@ database_cache_kara(volatile sqlite3 *db, int id)
return database_get_kara_##what##_id(db, id, what); \
}
___cache_
operation_db_function
(
_get_
,
mtime
,
*
);
___cache_
operation_db_function
(
_get_
,
duration
,
*
);
___cache_
operation_db_function
(
_set_
,
mtime
,
NOTHING
);
___cache_
operation_db_function
(
_set_
,
duration
,
NOTHING
);
___cache_
set_from_id
(
mtime
);
___cache_
set_from_id
(
duration
);
___cache_
get_from_id
(
mtime
);
___cache_
get_from_id
(
duration
);
___cache_get_from_path
(
mtime
);
___cache_get_from_path
(
duration
);
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