Skip to content

Commit

Permalink
pruned changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
RishabhSaini committed May 19, 2023
1 parent aba33a0 commit 6901fae
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
20 changes: 18 additions & 2 deletions rust/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ pub fn container_encapsulate(args: Vec<String>) -> CxxResult<()> {
});

let mut lowest_change_time = None;
let mut highest_change_time = None;
let mut package_meta = HashMap::new();
for pkg in pkglist.iter() {
let name = pkg.child_value(0);
Expand All @@ -277,33 +278,48 @@ pub fn container_encapsulate(args: Vec<String>) -> CxxResult<()> {
} else {
lowest_change_time = Some((Rc::clone(&nevra), pkgmeta.buildtime()))
}
if let Some(hightime) = highest_change_time.as_mut() {
if *hightime > buildtime {
*hightime = buildtime;
}
} else {
highest_change_time = Some(pkgmeta.buildtime())
}
state.rpmsize += pkgmeta.size();
package_meta.insert(nevra, pkgmeta);
}

// SAFETY: There must be at least one package.
let (lowest_change_name, lowest_change_time) =
lowest_change_time.expect("Failed to find any packages");
let highest_change_time = highest_change_time.expect("Failed to find any packages");

// Walk over the packages, and generate the `packagemeta` mapping, which is basically a subset of
// package metadata abstracted for ostree. Note that right now, the package metadata includes
// both a "unique identifer" and a "human readable name", but for rpm-ostree we're just making
// those the same thing.
for (nevra, pkgmeta) in package_meta.iter() {
let buildtime = pkgmeta.buildtime();
let change_time_offset_secs: u32 = buildtime
.checked_sub(lowest_change_time)
.checked_sub(lowest_change_time
.unwrap()
.try_into()
.unwrap();
// Convert to hours, because there's no strong use for caring about the relative difference of builds in terms
// of minutes or seconds.
let change_time_offset = change_time_offset_secs / (60 * 60);
let changelogs = pkgmeta.changelogs();
let pruned_changelogs: Vec<&u64> = changelogs.iter().filter(|e| {
let curr_build = glib::DateTime::from_unix_utc(**e as i64).unwrap();
let highest_time_build = glib::DateTime::from_unix_utc(highest_change_time as i64).unwrap();
highest_time_build.difference(&curr_build).as_days() <= 365_i64
}).collect();
state.packagemeta.insert(ObjectSourceMeta {
identifier: Rc::clone(nevra),
name: Rc::from(libdnf_sys::hy_split_nevra(&nevra)?.name),
srcid: Rc::from(pkgmeta.src_pkg().to_str().unwrap()),
change_time_offset,
change_frequency: pkgmeta.change_frequency(),
change_frequency: pruned_changelogs.len() as u32,
});
}

Expand Down
2 changes: 1 addition & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ pub mod ffi {
// Methods on PackageMeta
fn size(self: &PackageMeta) -> u64;
fn buildtime(self: &PackageMeta) -> u64;
fn change_frequency(self: &PackageMeta) -> u32;
fn changelogs(self: &PackageMeta) -> Vec<u64>;
fn src_pkg(self: &PackageMeta) -> &CxxString;
}

Expand Down
18 changes: 7 additions & 11 deletions src/libpriv/rpmostree-refts.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* Boston, MA 02111-1307, USA.
*/

#include <vector>

#include "config.h"

#include "rpmostree-refts.h"
Expand Down Expand Up @@ -124,31 +126,25 @@ RpmTs::package_meta (const rust::Str name) const
retval->_buildtime = headerGetNumber (h, RPMTAG_BUILDTIME);
retval->_src_pkg = headerGetString (h, RPMTAG_SOURCERPM);

// Get the update frequency of the package from changelogs
// Get the changelogs
struct rpmtd_s nchanges_date_s;
_cleanup_rpmtddata_ rpmtd nchanges_date = NULL;
nchanges_date = &nchanges_date_s;
headerGet (h, RPMTAG_CHANGELOGTIME, nchanges_date, HEADERGET_MINMEM);
int ncnum = rpmtdCount (nchanges_date);
if (!ncnum)
ncnum = 0;
int frequency_recent_updates = 0;
GDateTime *now_dt = g_date_time_new_now_utc ();

std::vector<uint64_t> epochs;
while (ncnum > 0)
{
uint64_t nchange_date = 0;
rpmtdNext (nchanges_date);
nchange_date = rpmtdGetNumber (nchanges_date);
GDateTime *build_dt = g_date_time_new_from_unix_utc (nchange_date);
// Ignore updates older than a year since they are irrelevant in
// describing the probability that the package will get updated again
if (g_date_time_compare (build_dt, g_date_time_add_years (now_dt, -1)))
{
frequency_recent_updates++;
}
epochs.push_back (nchange_date);
--ncnum;
}
retval->_change_frequency = frequency_recent_updates;
retval->_changelogs = epochs;
}
else
{
Expand Down
9 changes: 5 additions & 4 deletions src/libpriv/rpmostree-refts.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <gio/gio.h>
#include <libdnf/libdnf.h>
#include <memory>
#include <vector>

G_BEGIN_DECLS

Expand All @@ -52,7 +53,7 @@ struct PackageMeta
{
uint64_t _size;
uint64_t _buildtime;
uint32_t _change_frequency;
std::vector<uint64_t> _changelogs;
std::string _src_pkg;

uint64_t
Expand All @@ -65,10 +66,10 @@ struct PackageMeta
{
return _buildtime;
};
uint32_t
change_frequency () const
std::vector<uint64_t>
changelogs () const
{
return _change_frequency;
return _changelogs;
};

const std::string &
Expand Down

0 comments on commit 6901fae

Please sign in to comment.