Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
parlote-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
parlote-facil
Validations
c2bb483b
Valider
c2bb483b
rédigé
13 years ago
par
Ilya Zhitomirskiy
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
dg iz updating authors cache on creation of a post
parent
dfd65c4b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
app/models/post.rb
+17
-0
17 ajouts, 0 suppression
app/models/post.rb
spec/lib/stream/tag_stream_spec.rb
+0
-7
0 ajout, 7 suppressions
spec/lib/stream/tag_stream_spec.rb
spec/models/post_spec.rb
+67
-0
67 ajouts, 0 suppression
spec/models/post_spec.rb
avec
84 ajouts
et
7 suppressions
app/models/post.rb
+
17
−
0
Voir le fichier @
c2bb483b
...
...
@@ -32,6 +32,8 @@ class Post < ActiveRecord::Base
validates
:guid
,
:uniqueness
=>
true
after_create
:cache_for_author
#scopes
scope
:all_public
,
where
(
:public
=>
true
,
:pending
=>
false
)
scope
:includes_for_a_stream
,
includes
({
:author
=>
:profile
},
:mentions
=>
{
:person
=>
:profile
})
#note should include root and photos, but i think those are both on status_message
...
...
@@ -156,4 +158,19 @@ class Post < ActiveRecord::Base
self
.
class
.
where
(
:id
=>
self
.
id
).
update_all
(
:comments_count
=>
self
.
comments
.
count
)
end
# @return [Boolean]
def
cache_for_author
if
self
.
should_cache_for_author?
cache
=
RedisCache
.
new
(
self
.
author
.
owner
,
'created_at'
)
cache
.
add
(
self
.
created_at
.
to_i
,
self
.
id
)
end
true
end
# @return [Boolean]
def
should_cache_for_author?
self
.
triggers_caching?
&&
RedisCache
.
configured?
&&
RedisCache
.
acceptable_types
.
include?
(
self
.
type
)
&&
user
=
self
.
author
.
owner
end
end
Ce diff est replié.
Cliquez pour l'agrandir.
spec/lib/stream/tag_stream_spec.rb
+
0
−
7
Voir le fichier @
c2bb483b
...
...
@@ -10,11 +10,4 @@ describe TagStream do
describe
'shared behaviors'
do
it_should_behave_like
'it is a stream'
end
describe
'posts'
do
it
'explains the query'
do
puts
@stream
.
posts
.
to_sql
end
end
end
Ce diff est replié.
Cliquez pour l'agrandir.
spec/models/post_spec.rb
+
67
−
0
Voir le fichier @
c2bb483b
...
...
@@ -137,4 +137,71 @@ describe Post do
Post
.
new
.
triggers_caching?
.
should
be_true
end
end
describe
"after_create"
do
it
"calls cache_for_author only on create"
do
post
=
Factory
.
build
(
:status_message
,
:author
=>
bob
.
person
)
post
.
should_receive
(
:cache_for_author
).
once
post
.
save
post
.
save
end
end
describe
'#cache_for_author'
do
before
do
@post
=
Factory
.
build
(
:status_message
,
:author
=>
bob
.
person
)
@post
.
stub
(
:should_cache_for_author?
).
and_return
(
true
)
end
it
'caches with valid conditions'
do
cache
=
mock
.
as_null_object
RedisCache
.
should_receive
(
:new
).
and_return
(
cache
)
cache
.
should_receive
(
:add
)
@post
.
cache_for_author
end
it
'does nothing if should not cache'
do
@post
.
stub
(
:should_cache_for_author?
).
and_return
(
false
)
RedisCache
.
should_not_receive
(
:new
)
@post
.
cache_for_author
end
end
describe
"#should_cache_for_author?"
do
before
do
@post
=
Factory
.
build
(
:status_message
,
:author
=>
bob
.
person
)
RedisCache
.
stub
(
:configured?
).
and_return
(
true
)
RedisCache
.
stub
(
:acceptable_types
).
and_return
([
'StatusMessage'
])
@post
.
stub
(
:triggers_caching?
).
and_return
(
true
)
end
it
'returns true under valid conditions'
do
@post
.
should_cache_for_author?
.
should
be_true
end
it
'does not cache if the author is not a local user'
do
@post
.
author
=
Factory
(
:person
)
@post
.
should_cache_for_author?
.
should
be_false
end
it
'does not cache if the cache is not configured'
do
RedisCache
.
stub
(
:configured?
).
and_return
(
false
)
@post
.
should_cache_for_author?
.
should
be_false
end
it
'does not cache if the object does not triggers caching'
do
@post
.
stub
(
:triggers_caching?
).
and_return
(
false
)
@post
.
should_cache_for_author?
.
should
be_false
end
it
'does not cache if the object is not of an acceptable cache type'
do
@post
.
stub
(
:type
).
and_return
(
"Photo"
)
@post
.
should_cache_for_author?
.
should
be_false
end
end
#user exists,
# cache configured,
# triggers caching,
# of the cachable type
end
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