Skip to content

Commit

Permalink
#99: Fix copying implementations in relation to delta
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-sita committed Jan 6, 2025
1 parent 4af24fb commit fb32fe1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,53 +321,45 @@ private Void updateImageDeltaDuplicate(Set<UUID> newImageIds, ReplicationParam.D
}

private Void updateImageDeltaFillChildRepo(Set<UUID> newImageIds, ReplicationParam.FillChildRepo fillChildRepo) {
for (Set<UUID> ids : partition(newImageIds)) {
// let's use data of original, it's the same but doesn't require recalculation like view does. Match by reference_id

Image origin = IMAGE.as("origin");
Image copy = IMAGE.as("copy");

var ref = new Object() {
InsertValuesStep4<TagDeltaRecord, UUID, Boolean, String, String> ongoing = dslContext
.insertInto(Tables.TAG_DELTA)
.columns(Tables.TAG_DELTA.IMAGE_ID, Tables.TAG_DELTA.ADDS, Tables.TAG_DELTA.CATEGORY, Tables.TAG_DELTA.TAG);
};

dslContext
.select(Tables.TAG_DELTA.ADDS, Tables.TAG_DELTA.CATEGORY, Tables.TAG_DELTA.TAG, copy.ID, origin.ID)
.from(Tables.TAG_DELTA)
.join(origin).on(Tables.TAG_DELTA.IMAGE_ID.eq(origin.ID))
.join(copy).on(copy.REFERENCE_ID.eq(origin.REFERENCE_ID))
.where(copy.ID.in(ids))
.fetch()
.forEach(record -> {
ref.ongoing = ref.ongoing
.values(record.get(origin.ID), record.get(Tables.TAG_DELTA.ADDS), record.get(Tables.TAG_DELTA.CATEGORY), record.get(Tables.TAG_DELTA.TAG));
});

ref.ongoing.execute();
}

return null;
}

private Void updateImageDeltaHardCopyToNewRepo(Set<UUID> newImageIds, ReplicationParam.HardCopyToNewRepo hardCopyToNewRepo) {
Image origin = IMAGE.as("origin");
Image copy = IMAGE.as("copy");

for (Set<UUID> ids : partition(newImageIds)) {

var ref = new Object() {
InsertValuesStep4<TagDeltaRecord, UUID, Boolean, String, String> ongoing =
dslContext
.insertInto(Tables.TAG_DELTA)
.columns(Tables.TAG_DELTA.IMAGE_ID, Tables.TAG_DELTA.ADDS, Tables.TAG_DELTA.CATEGORY, Tables.TAG_DELTA.TAG);
};

UUID originRepoId = hardCopyToNewRepo.sourceRepoId();
// let's copy by referencable ID
Map<UUID, UUID> copyToOriginId = dslContext
.select(copy.ID, origin.ID)
.from(copy)
.join(origin).on(copy.REFERENCE_ID.eq(origin.REFERENCE_ID))
.where(copy.ID.in(ids))
.and(origin.REPOSITORY_ID.eq(originRepoId))
.fetch()
.intoMap(copy.ID, origin.ID);

Set<UUID> originIds = new HashSet<>(copyToOriginId.values());

dslContext
.select(Tables.TAG_DELTA_CALC.IMAGE_ID, Tables.TAG_DELTA_CALC.ADDED, Tables.TAG_DELTA_CALC.CATEGORY, Tables.TAG_DELTA_CALC.TAG)
.from(Tables.TAG_DELTA_CALC)
.where(Tables.TAG_DELTA_CALC.IMAGE_ID.in(ids))
.select(Tables.TAG_DELTA.IMAGE_ID, Tables.TAG_DELTA.ADDS, Tables.TAG_DELTA.CATEGORY, Tables.TAG_DELTA.TAG)
.from(Tables.TAG_DELTA)
.where(Tables.TAG_DELTA.IMAGE_ID.in(originIds))
.fetch()
.forEach(record -> {
ref.ongoing = ref.ongoing
.values(record.get(Tables.TAG_DELTA_CALC.IMAGE_ID), record.get(Tables.TAG_DELTA_CALC.ADDED), record.get(Tables.TAG_DELTA_CALC.CATEGORY), record.get(Tables.TAG_DELTA_CALC.TAG));
ref.ongoing = ref.ongoing.values(copyToOriginId.get(record.get(Tables.TAG_DELTA.IMAGE_ID)), record.get(Tables.TAG_DELTA.ADDS), record.get(Tables.TAG_DELTA.CATEGORY), record.get(Tables.TAG_DELTA.TAG));
});

ref.ongoing.execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ record TagViewId(String value, UUID categoryId) { }
row(TAG.VALUE, TAG.TAG_CATEGORY_ID)
.in(uniqueTagIds.stream().map(tagViewId -> row(tagViewId.value(), tagViewId.categoryId())).toList())
)
.fetch();
.fetch(); // 75 seconds. Maybe missing idx?

Map<Tag, UUID> tagIds = new HashMap<>();

Expand Down Expand Up @@ -209,7 +209,7 @@ public void accept(UUID uuid, Consumer<ImageTag> consumer) {
row(Tables.IMAGE_TAGS.IMAGE_ID)
.in(batchOfImages.stream().map(id -> row(id)).toList())
)
.fetch()
.fetch() // todo: seemingly after adding indexes it went from 150s to 220s. Why?
.forEach(rr -> {
UUID imageId = rr.value1();
String tag = rr.value2();
Expand All @@ -232,7 +232,7 @@ public void accept(UUID uuid, Consumer<ImageTag> consumer) {
ongoing = ongoing.values(tagId, imageId);
toPersist++;
if (toPersist > tagRepositoryProperties.getTagBulkSize()) {
int c = ongoing.execute();
int c = ongoing.execute(); // 30s
if (c != toPersist) {
throw new RuntimeException();
}
Expand Down

0 comments on commit fb32fe1

Please sign in to comment.