<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bogdanov Anton</title>
    <description>The latest articles on DEV Community by Bogdanov Anton (@kortirso).</description>
    <link>https://dev.to/kortirso</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1313195%2Feea2bfb6-c04c-4fe3-a381-e87da9105bf5.jpeg</url>
      <title>DEV Community: Bogdanov Anton</title>
      <link>https://dev.to/kortirso</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kortirso"/>
    <language>en</language>
    <item>
      <title>Prevent over-fetching data for REST API in Ruby on Rails</title>
      <dc:creator>Bogdanov Anton</dc:creator>
      <pubDate>Tue, 12 Mar 2024 07:26:49 +0000</pubDate>
      <link>https://dev.to/kortirso/prevent-over-fetching-data-for-rest-api-3ogb</link>
      <guid>https://dev.to/kortirso/prevent-over-fetching-data-for-rest-api-3ogb</guid>
      <description>&lt;p&gt;One of the main features of GrahpQL compared to the REST api - GraphQL APIs let clients query the exact data they need, while REST APIs just returns all data described in serializers.&lt;/p&gt;

&lt;p&gt;While I prefer using REST API for my rails apps I tried to find solution for optimizing responses. I made some attempts with multiple serializers for different controllers and for the same models, but it leds to mess.&lt;/p&gt;

&lt;p&gt;With using &lt;a href="https://github.com/jsonapi-serializer/jsonapi-serializer"&gt;jsonapi-serializer&lt;/a&gt; I found solution.&lt;/p&gt;

&lt;p&gt;Attributes of serializer can be optional with if and proc&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class UserSerializer &amp;lt; ApplicationSerializer
  attribute :confirmed, if: proc { |_, params| required_field?(params, 'confirmed') }, &amp;amp;:confirmed?
  attribute :banned, if: proc { |_, params| required_field?(params, 'banned') }, &amp;amp;:banned?
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During serialization such attributes will be or will not be serialized based on provided params.&lt;/p&gt;

&lt;p&gt;Attribute will be serialized if it presents in include_fields or does not present in exclude_fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationSerializer
  def self.required_field?(params, field_name)
    params[:include_fields]&amp;amp;.include?(field_name) || params[:exclude_fields]&amp;amp;.exclude?(field_name)
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is how part in controllers works&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SERIALIZER_FIELDS = %w[confirmed banned].freeze
def index
  render json: {
    user: UserSerializer.new(
      current_user, params: serializer_fields(UserSerializer, SERIALIZER_FIELDS)
    ).serializable_hash
  }, status: :ok
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Method serializer_fields generates hash with include/exclude attributes based on params and compares it with available attributes from serializer. Later that hash is used in serializer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def serializer_fields(serializer_class, default_include_fields=[])
  @serializer_attributes = serializer_class.attributes_to_serialize.keys.map(&amp;amp;:to_s)
  return {} if response_include_fields.any? &amp;amp;&amp;amp; response_exclude_fields.any?
  return { include_fields: response_include_fields } if response_include_fields.any?
  return { exclude_fields: response_exclude_fields } if response_exclude_fields.any?
  return { include_fields: default_include_fields } if default_include_fields.any?

  {}
end

def response_include_fields
  @response_include_fields ||= params[:response_include_fields]&amp;amp;.split(',').to_a &amp;amp; @serializer_attributes
end

def response_exclude_fields
  @response_exclude_fields ||= params[:response_exclude_fields]&amp;amp;.split(',').to_a &amp;amp; @serializer_attributes
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach allows to achieve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;preventing over-fetching data by REST API,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;tracking required attributes for responses (maybe some of them are not used at all),&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;usually controller could have some .includes for optimization, and based on required attributes such optimizations/additional requests to DB can be skipped.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this approach will help somebody with REST API optimization their Rails apps. &lt;/p&gt;

</description>
      <category>rails</category>
      <category>api</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Better UI for Que background jobs adapter</title>
      <dc:creator>Bogdanov Anton</dc:creator>
      <pubDate>Sun, 03 Mar 2024 05:39:43 +0000</pubDate>
      <link>https://dev.to/kortirso/better-ui-for-que-background-jobs-adapter-d26</link>
      <guid>https://dev.to/kortirso/better-ui-for-que-background-jobs-adapter-d26</guid>
      <description>&lt;p&gt;Good day, Rails devs!&lt;/p&gt;

&lt;p&gt;In my rails apps for background jobs I use mostly Que adapter, and for checking jobs status through UI only Que::Web was available.&lt;/p&gt;

&lt;p&gt;Some time ago I got difficults with updating apps to rack 3 because of Que::Web's Sinatra, and decided to make own UI as simple Rails engine. So let me introduce &lt;a href="https://github.com/kortirso/que-view"&gt;Que::View&lt;/a&gt; - new UI interface for Que jobs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hzhbrs6nkc5818abnpr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hzhbrs6nkc5818abnpr.png" alt="Viewing jobs list" width="800" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No more redundant dependencies, much freshier gem (Que::Web was not updated last 2 years). I hope it would be useful for those who use Que adapter.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Get the PR statistics from Github with PullKeeper</title>
      <dc:creator>Bogdanov Anton</dc:creator>
      <pubDate>Fri, 01 Mar 2024 10:14:04 +0000</pubDate>
      <link>https://dev.to/kortirso/get-the-pr-statistics-from-github-with-pullkeeper-4d27</link>
      <guid>https://dev.to/kortirso/get-the-pr-statistics-from-github-with-pullkeeper-4d27</guid>
      <description>&lt;p&gt;In the process of growing a development team, sometimes it becomes necessary to have some way to calculate the effectiveness of developers, compare them with each other, motivate them, encourage and punish (maybe, sometimes).&lt;/p&gt;

&lt;p&gt;And if the quality of the code is a rather difficult thing to calculate, then the quality and speed of reviewing of pull requests can be calculated. In our company first we started to use a pull request stats package that integrates with github actions and publishes review statistics directly in pull requests. But we had some issues and incorrect calculations.&lt;/p&gt;

&lt;p&gt;We thought that those library technically can not meet our needs, then why not make our own web service, for example with Ruby on Rails, a couple of weeks of work and we had the &lt;a href="https://pullkeeper.dev"&gt;PullKeeper&lt;/a&gt; — &lt;a href="https://github.com/kortirso/pullmetry"&gt;open source&lt;/a&gt; application for getting relevant statistics about PRs, reviewers and comments. Now all statistics can be collected in one place, conveniently divided into statistics for individual repositories and for the whole company. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl3ldo0ltpwqv33hcsvc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl3ldo0ltpwqv33hcsvc1.png" alt="Company insights example" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Аfter 1 year of improving PullKeeper right now tracks 12 developer metrics and 10 repository metrics, so team leads and project managers can very accurate measure their teams in reviewing PRs, find weak places, maybe review process spends huge amount of time (PRs have low code quality), or testing is long process - so features are delivered not so fast to production.&lt;/p&gt;

&lt;p&gt;Main feature of PullKeeper that allows accurately calculate review time is excluding not-working time of developers (in compare with other solutions), by default night time is already excluded from calculations, and in addition there is option to specify company's working time.&lt;/p&gt;

&lt;p&gt;Additional features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;all statistics refreshes automatically, no need to wait new open PR for refreshing it,&lt;/li&gt;
&lt;li&gt;for each company you can specify non-working hours (only working time can be taken into account when calculating the time spent on review),&lt;/li&gt;
&lt;li&gt;it works with Github and Gitlab,&lt;/li&gt;
&lt;li&gt;you can choose statistics to display in the tables,&lt;/li&gt;
&lt;li&gt;you can also choose to render statistics of changes in efficiency compared to the previous period,&lt;/li&gt;
&lt;li&gt;if developer login into the application he will receive read access to all repositories and companies where he has insights,&lt;/li&gt;
&lt;li&gt;sending statistics to Slack/Discord/Telegram channels, so you don’t need to log into the application to check statistics,&lt;/li&gt;
&lt;li&gt;achievements system for representing and comparing developer success.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The application is &lt;a href="https://github.com/kortirso/pullmetry"&gt;open source&lt;/a&gt;, you can check it, leave feedback, describe bugs or ask to integrate new features.&lt;/p&gt;

&lt;p&gt;A few companies started to use it, if you find PullKeeper useful too - it will make me a little happier.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>rails</category>
      <category>github</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
