Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F13521420
counter_cache.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
996 B
Referenced Files
None
Subscribers
None
counter_cache.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.CounterCache
do
alias
Pleroma.CounterCache
alias
Pleroma.Repo
use
Ecto.Schema
import
Ecto.Changeset
import
Ecto.Query
schema
"counter_cache"
do
field
(
:name
,
:string
)
field
(
:count
,
:integer
)
end
def
changeset
(
struct
,
params
)
do
struct
|>
cast
(
params
,
[
:name
,
:count
])
|>
validate_required
([
:name
])
|>
unique_constraint
(
:name
)
end
def
get_as_map
(
names
)
when
is_list
(
names
)
do
CounterCache
|>
where
([
cc
],
cc
.
name
in
^
names
)
|>
Repo
.
all
()
|>
Enum
.
group_by
(
&
&1
.
name
,
&
&1
.
count
)
|>
Map
.
new
(
fn
{
k
,
v
}
->
{
k
,
hd
(
v
)}
end
)
end
def
set
(
name
,
count
)
do
%
CounterCache
{}
|>
changeset
(%{
"name"
=>
name
,
"count"
=>
count
})
|>
Repo
.
insert
(
on_conflict
:
[
set
:
[
count
:
count
]],
returning
:
true
,
conflict_target
:
:name
)
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Sun, Dec 7, 8:19 PM (8 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
634144
Default Alt Text
counter_cache.ex (996 B)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment