coderplanets / coderplanets_server Goto Github PK
View Code? Open in Web Editor NEWcoderplanets.com API(GraphQL) server, build with elixir, phoenix, absinthe
Home Page: https://api.coderplanets.com/graphiql
License: Apache License 2.0
coderplanets.com API(GraphQL) server, build with elixir, phoenix, absinthe
Home Page: https://api.coderplanets.com/graphiql
License: Apache License 2.0
when query read=true, i can use:
read == true ->
queryable
|> join(:inner, [content, f, c], viewers in assoc(content, :viewers))
|> where([content, f, c, viewers], viewers.user_id == ^user.id)
but came to read=false, this is not work as except
read == true ->
queryable
|> join(:inner, [content, f, c], viewers in assoc(content, :viewers))
|> where([content, f, c, viewers], viewers.user_id != ^user.id)
because the viewers
assoc only have records of viewed user, the unviewed user is not in that table
left_join is not working either, need help...
like react-gh-like-diff
handle situation like
a possible inner logger table for post would be like this:
post_loggers
:
post_id | user_id | action | old_content | new_content | reason |
---|---|---|---|---|---|
xx | xx | lock | .. | .. | solved |
xx | xx | edit | old blabla | new blabla | ... |
reason:
some code like
field :paged_posts, :paged_posts do
arg(:filter, non_null(:paged_article_filter))
middleware(M.PageSizeProof)
resolve(&Resolvers.CMS.paged_posts/3)
middleware(M.FormatPagination)
end
some file like
page_post_test
has lots of boilerplate code with job
, video
, repo
... should use macro to reduce it
see https://github.com/coderplanets/coderplanets_web/issues/354
details:
should have robot system to do the chores, like(not limit to):
TODO
to avoid massive trash / unrelated content(post, job, ... etc) publish in short time.
let's set a time limit in a row of publish articles.
add a table to statistics
module to log the user publish behavior , then use a middleware to diff time between now
and latest publish time
.
Due to varying limits on the maximum size of URLs, we recommend using one of the POST options below instead, putting the query into the body of the request.
article-like content will freeze after a day / week, if owner want to update after the limit date, the updated content can only go to the attachment field which will display "update/更新" on the front-end page.
when a article-like content in follow situations:
we should set a 🔒 flag on the content, and no edit or comments will be made/append
a possible prototype may look like this:
field(:lock, :string)
belongs_to(:lock_operator, User)
and if front-end want the lock history, should check the inner-logger, see: #104
currently the pin contents execs 2 query on the same contents table:
def paged_contents(queryable, filter) do
queryable
|> flag_query(filter)
|> ORM.find_all(filter)
|> add_pin_contents_ifneed(queryable, filter)
end
defp flag_query(queryable, filter, flag \\ %{}) do
flag = %{pin: false, trash: false} |> Map.merge(flag)
# NOTE: this case judge is used for test case
case filter |> Map.has_key?(:community) do
true ->
queryable
|> join(:inner, [q], f in assoc(q, :community_flags))
|> where([q, f], f.pin == ^flag.pin and f.trash == ^flag.trash)
|> join(:inner, [q, f], c in assoc(f, :community))
|> where([q, f, c], c.raw == ^filter.community)
false ->
queryable
end
end
defp add_pin_contents_ifneed(contents, queryable, filter) do
with {:ok, normal_contents} <- contents,
true <- Map.has_key?(filter, :community),
true <- 1 == Map.get(normal_contents, :page_number) do
{:ok, pined_content} =
queryable
|> flag_query(filter, %{pin: true})
|> ORM.find_all(filter)
# TODO: add hot post pin/trash state ?
# don't by flag_changeset, dataloader make things complex
concat_contents(pined_content, normal_contents)
else
_error ->
contents
end
end
when the contents table growing big, the "add_pin_contents_ifneed" function will query all the contents only for few pined contents, this's may have performance issue.
i think the better practice is: we split pined contents into a new separate table, then combine the small pined query results to all the results.
reference:
hexdoc typespeccs
specifications-types-elixir
elixir school
official doc
realworld example:
code-corps-api
nested_filter
tesla
credo vs Dialyzer
use dialyxir in elixir
phoenix quick start
Currently the xxx-users loader is not using Dataloader , because the limit and offset in the query will affect the whole result set and not each association, this can be solved by a "Top N per Group" case, but the syntax is ugly ...
reference links:
https://elixirforum.com/t/preloading-top-comments-for-posts-in-ecto/1052/8
elixir-ecto/ecto#2281
https://spin.atomicobject.com/2016/03/12/select-top-n-per-group-postgresql/
https://stackoverflow.com/questions/40529699/how-to-select-id-with-max-date-group-by-category-in-ecto-query-with-phoenix
http://www.achraf-sallemi.com/select-top-n-per-group-in-postgresql/
use customize scrivener to remove FormatPagination middleware
first of all: video should be links, i am poor ..
post
, duration
, desc
, source
, source_link
, published_at
,video_author
but NOT playtimeswhen create comment to a Article, the Article's updated_at
field should be updated together, this is useful when use filter like latest-update to the articles list, which is default filter
see absinthe issue
(like / star / comment) by sb => reputation +1
(favorite) by sb => reputation +2
currently delivery context uses cms's passport system, should make one for delivery.
display recent messages/activity in twitter/weibo/youtube ... etc
see coderplanets/coderplanets_web#990
drop apollo schema for now
# - apollo schema:check --endpoint="http://apiraw.coderplanets.com/graphiql"
# - apollo schema:publish --endpoint="http://apiraw.coderplanets.com/graphiql"
since i register groupher.com domain, it's time to change the project namespace to Groupher.
phoenix 1.4 came with better http/2.0 support, and it's upgrade guide seems has no breaking change.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.